Announcement

Collapse
No announcement yet.

Stepping through an XML document...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Stepping through an XML document...

    Hey folks,

    Playing around and just trying to broaden scripting skills, I was trying to repurpose the sysmon.txt script to try and read an XML weather file. I've managed to get it to see the XML file and even pull the first record's worth of Data out but have been stuck since then.

    The challenge I believe is that sysmon.txt looks at the coolmon.xml file which is all displayed on one line. But the XML file I have has multiple lines. If I modify the XML file so that the first two tags are on the same line I can pull from both, but if I revert it back to it's original format I lose the second tag.

    What's the command to make the script look at the next line? I know there's *.readline, *.skipline but *.nextline / *.movenext doesn't produce any results.

    Suggestions?

    =====

    script:

    sub main ()
    dim f, fs
    dim city,province,celsius,fahrenheit,conditions,dewpoint,relativ ehumidty,wind,barometricpressure
    dim windchill,humidex,icon,lastupdate,source


    Set fs=CreateObject("Scripting.FileSystemObject")
    set f=fs.OpenTextFile("c:\program files\homeseer\scripts\ontario-toronto.xml")
    f.skipline
    f.skipline
    data1=f.readall

    city=hs.StringItem(data1,1,"</name>")
    city=hs.StringItem(city,2,"<name>")


    state=hs.StringItem(data1,1,"</state>")
    state=hs.StringItem(state,2,"<state>")


    hs.setdevicestring "w16","hey" & city & "",true
    hs.setdevicestring "w17","hey" & province & "",true

    XML:

    <?xml version="1.0" ?>
    - <city>
    <name>Toronto</name>
    <state>Ontario</state>
    - <temperatures>
    <fahrenheit>46</fahrenheit>
    <celsius>7</celsius>
    </temperatures>
    <conditions>Mostly Sunny</conditions>
    <dewpoint>30</dewpoint>
    <relative_humidity>53</relative_humidity>
    <wind>SW15G22</wind>
    <barometric_pressure>30.00F</barometric_pressure> <notes />
    <wind_chill_fahrenheit>Not Applicable</wind_chill_fahrenheit>
    <heat_index_fahrenheit>Not Applicable</heat_index_fahrenheit>
    <image>http://www.srh.noaa.gov/weather/imag...</image>
    <last_updated>November 26, 2003 17:25:09 GMT</last_updated>
    <last_updated_seconds_gmt>1069885509</last_updated_seconds_gmt>
    <info_courtesy_of>The National Weather Service</info_courtesy_of>
    <feed_problems_contact>weather@boygenius.com</feed_problems_contact>
    <xml_generation_script_author>Todd Finney, Boy Genius Incorporated</xml_generation_script_author>
    </city>
Working...
X