tiistai 14. lokakuuta 2014

Javascript applications

So I have been learning Javascript for a while now and I'm getting it slowly. But still it feels so hard. I completed codeacademy.com Javascript course and had some other things to read. So far I have quickly developed three little things.

First one is rock, scissors, paper game. Simple game. Try the demoversion here: http://84.251.124.101/~shnigi/kivisaksipaperi/pewi.html


Next one is coinflipper. Select your side and flip it here: http://84.251.124.101/~shnigi/kolikonheitto/


Last one is Lotto-machine where you enter 4 different things and the machine tells you which one is best. Try it here: http://84.251.124.101/~shnigi/lottokone/

I'm planning to do a mobile app (Android) later from one of these.

perjantai 3. lokakuuta 2014

What is XML and how to use

XML was designed to describe data. With XML one can for example change data between two systems running on different platform and code. XML does not do anything. XML needs to be manipulated that it can be used. Here is an example of XML file from W3 schools:

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

XSD is somekind of file that defines how XML file should be formatted. For example elements are defined as string and should be manipulated as string.

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

XML and XSD files can be easily generated from online converters. Next is XSLT file which is used to select data and define how it is generated in HTML file. To define the XSLT file which will be used to convert the XML file to HTML use this tag

<?xml-stylesheet href="filename.xslt" type="text/xsl" ?>

To select values from XML file with XSLT one can put HTML tags inside XSLT and then use for example for each loop to select all items. In the select tag is the "path" to the thing that should be selected. If the XML file path has "properties" use @ to select the property. Example of XSLT file:

<div>
<xsl:for-each select="sports-content/tournament/tournament-division/tournament-round">
<h3> 
<xsl:value-of select="tournament-round-metadata/site/site-metadata/home-location/@city"/>
<xsl:value-of select="tournament-round-metadata/site/site-metadata/home-location/@country"/>
</h3> 
 </div>

Then open the XML file with web browser and if it is correctly set up it will show up as HTML. Tada!


As IDE I use Eclipse. For more information check W3 Schools. I find XML hard to understand. But for example data could be changed from PHP program to Java program with XML.