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:

Next one is coinflipper. Select your side and flip it here:

Last one is Lotto-machine where you enter 4 different things and the machine tells you which one is best. Try it here:

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:

  <body>Don't forget me this weekend!</body>

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: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"/>

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:

<xsl:for-each select="sports-content/tournament/tournament-division/tournament-round">
<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"/>

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.