In this sample we read a XML-file with several attributes into Clarion.
This example was written by Trevor Dickson, Capetown, ZA.
I added some comments and icons, you can download the entire folder here.
In a simple xml file with clearer names, the order of the variables in your group or queue doesnt really matter that much, but in this case the order is crucial and it seems you need to define all the fields, although you only may need some, else the order goes out.
Here you see the XML-file which is received:
<aws:weather xmlns:aws="http://www.aws.com/aws"> <aws:api version="2.0" /> <aws:WebURL>http://weather.weatherbug.com/Canada/Wiarton-weather.html?ZCode=Z5546&Units=1&stat=CYVV</aws:WebURL> <aws:InputLocationURL>http://weather.weatherbug.com/Canada/Wiarton-weather.html?ZCode=Z5546&Units=1</aws:InputLocationURL> <aws:station requestedID="" id="CYVV" name="Wiarton Airport" city="Wiarton" state="Canada" citycode="CYVV" country="Canada" latitude="44.75" longitude="-81.0999984741211" /> <aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond001.gif">Cloudy</aws:current-condition> <aws:temp units="°C">15.0</aws:temp> <aws:rain-today units="mm">0.00</aws:rain-today> <aws:wind-speed units="km/h">13</aws:wind-speed> <aws:wind-direction>S</aws:wind-direction> <aws:gust-speed units="km/h">14</aws:gust-speed> <aws:gust-direction>SE</aws:gust-direction> </aws:weather>
From the capesoft xfiles docs:
Notice also that the order of the fields is critical. Without the ability to match exclusively on the name, xFiles will take the order of the fields into account. Lastly notice that the attribute comes before the field. so the Type comes before the Price.
So in our case, the units will become before each weather description, e.g. Units and then Temp, Units and then Windspeed, etc Last thing to remember is that xml is case sensitive and to use the external name field
ResultGroup (GROUP) result:version result:api result:weburl result:station result:requestedID result:id result:name result:city result:state result:citycode result:latitude result:longitude result:currentCondition result:tempunits
-> units first External Name: units result:temp -> temperature after units External Name: aws:temp result:rainunits -> again units first External Name: units result:raintoday -> rain-today after units External Name: aws:rain-today result:windspeedunits result:windspeed result:gustspeedunits result:gustspeed result:gustdirection END
Thats mostly all! Add salt and pepper as you like....
You can download the entire folder as ZIP (2.6 MB).
NOTE: this example requires Capesofts Nettalk and xFiles!
Sample uploaded: 18. April 2010