Sign in to follow this  
Followers 0
SuperSearcher

Reading data from XML

8 posts in this topic

Ok, First Off: I used the search engine, looked in Example scripts, and read the DOM Wrapper UDF... I guess I just don't get it.

I can use AutoIt fairly well.. it's just been a while, I'm not a "coder", and I have a bad habbit of making things more complicated than they are.

All I want to do is read certain data from an XML file and move it to my own file to create my own table to be printed..

Here is the exact XML file I'm using:

<weatherbox>

<header>

<title>News 8 Austin Area Weather</title>

<location>http://www.news8austin.com/content/Weather/</location>

</header>

<weatherdata>

<date>Nov 22 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Cloud</image>

<temperature>60º</temperature>

<comment>Cloudy</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Xlite_Rain</image>

<temperature>53º</temperature>

<comment>30% Light Rain</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 23 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Day_Xlite_Rain</image>

<temperature>73º</temperature>

<comment>Cloudy... 30% Light Rain</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Xlite_Rain</image>

<temperature>62º</temperature>

<comment>20% Light Rain</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 24 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Day_Partly_Cloudy</image>

<temperature>74º</temperature>

<comment>20% Rain AM, Clearing PM, Turning Breezy</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Mostly_Clear</image>

<temperature>48º</temperature>

<comment>Mostly Clear</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 25 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Mostly_Sunny</image>

<temperature>70º</temperature>

<comment>Mostly Sunny</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Partly_Cloudy</image>

<temperature>51º</temperature>

<comment>Partly Cloudy</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 26 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Day_Partly_Cloudy</image>

<temperature>73º</temperature>

<comment>Increasing Clouds</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Mostly_Cloudy</image>

<temperature>57º</temperature>

<comment>Mostly Cloudy</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 27 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Day_Xlite_Rain</image>

<temperature>73º</temperature>

<comment>Mostly Cloudy... 30% Rain</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Xlite_Rain</image>

<temperature>62º</temperature>

<comment>30% Rain</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 28 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Day_Xlite_Rain</image>

<temperature>75º</temperature>

<comment>30% Showers/Storms</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Mostly_Clear</image>

<temperature>49º</temperature>

<comment>Mostly Clear, Breezy</comment>

</daypart>

</weatherdata>

<weatherdata>

<date>Nov 29 2008 12:00AM</date>

<daypart>

<header>Daytime</header>

<image>Mostly_Sunny</image>

<temperature>63º</temperature>

<comment>Mostly Sunny</comment>

</daypart>

<daypart>

<header>Nighttime</header>

<image>Night_Clear</image>

<temperature>42º</temperature>

<comment>Clear</comment>

</daypart>

</weatherdata>

</weatherbox>

As you can see, it's an 8 day forecast. Now, what I want to do is read all of the data to move the forecast to a different table, change the images (over 40) to my own (10) and be able to hand these out to people for an event, so I'm going to be printing it on business card size pieces of paper.

I tried using the buddylist (found through searching) example, but since it didn't show up anything I couldn't figure out how to use this as a template.

I also tried using _xmltest but that one just listed an array(?).. I don't want a number, I want the actual value.

Among others...

I guess I'm just asking what to use and a basic example - please. If I was a bit more intellectual then I wouldn't be asking, I guess. I just don't want to have to copy the XML feed, then use AutoIt to Find/Delete everything I don't need (ex: <header></header> So only Nighttime shows in my txt file) and then working from there. Instead I want to learn how to do this right for future reference and knowledge.

Flame away at my idiocy, and tell me to use the forum search.. but I read all 19 pages of XML and still don't get it - so obviously my brain just isn't wrapping around something.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It could be done by using a lot of stringsplit()

gimme a few minutes and I'll come up with a script.

as for the images... I see no images in the xml so I wouldn't know which to replace with what.

A suggestion too, wrap the xml file in

tags.
Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It could be done by using a lot of stringsplit()

gimme a few minutes and I'll come up with a script.

as for the images... I see no images in the xml so I wouldn't know which to replace with what.

Yeah, sorry. I actually got the direct link for XML from the local weather station and the guy also sent me links to every single icon they use, so for example where it says <image>Cloud</image> they have it setup to read that from /images/weather/forecast/Cloud.gif

So what you're saying is that I don't even need to use the DOMWrapper?

I'm actually going to be directly accessing their XML feed (link) which is updated 3 times a day. And my program will read it at 6:00am or 3:00pm (haven't decided yet) everyday and print out the forecast to hand to people for an event and I figured I could setup the program (easily) to say 'If line 32 says Cloud then insert 'image'. And for everything else it will be pretty much copy/paste.

Then of course, to include their business logo at the bottom (which was provided to me with all of the other information) and choose how many need to be printed manually, then have it print as a tile via MSWord to include 6-9 cards per page and then have them cut out to be handed out.

I know I can do everything else, I just don't get this XML thing.. but again, I am probably looking at it from the wrong perspective - I've been searching for XML help.. not string help.

Edit: I'm not seeing an edit button for my first post.. sorry about the code tags - err, lack thereof

Edited by SuperSearcher

Share this post


Link to post
Share on other sites

It could probably also be done in many, MANY different ways. I'm just seeing this for me as an experiment and a fun way to learn. Whether you'll use it is your choice :)


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It could probably also be done in many, MANY different ways. I'm just seeing this for me as an experiment and a fun way to learn. Whether you'll use it is your choice :)

I'm sure.. I just wanted somewhere to start from - the rest usually falls into place from there.

http://images.news8austin.com/media/xml/8dayforecast.xml is the direct link to XML feed.

I guess I'll start searching for string help via helpfile in the meantime to better understand how you are seeing my problem and maybe be able to see your solution from better eyes.

EDIT: AH! So do you think I should write a seperate function for stringtype, (ie: Header, date, image) and have it trimleft and trimright, as an array, then have it listed in an INI file under each one so image1: image2: image3: then have it read the ini file for each section to create the table?

I can do that! lol. Have it read the XML feed by line #. Then organize in an INI and then read the ini and put it in a premade MSWORD template table and just insert data and tile/print.

Thanks so much for getting my wheels turning, toonboon! I would still like to see what you come up with just to see a different solution. I'll be sure to post up what I come up with when done for further knowledge

Edited by SuperSearcher

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <array.au3>
InetGet("http://images.news8austin.com/media/xml/8dayforecast.xml", @TempDir & "Wheather.xml", 1)
$xml = FileRead(@TempDir & "wheather.xml")
$xml = StringSplit($xml, "<weatherdata>", 1)
_ArrayDelete($xml, 0)
_ArrayDelete($xml, 0)
Dim $days[8][7]

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "date>", 1)
    $days[$i][0] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "image>", 1)
    $days[$i][1] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "temperature>", 1)
    $days[$i][2] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "comment>", 1)
    $days[$i][3] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "image>", 1)
    $days[$i][4] = StringTrimRight($insert[4], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "temperature>", 1)
    $days[$i][5] = StringTrimRight($insert[4], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "comment>", 1)
    $days[$i][6] = StringTrimRight($insert[4], 2)
Next
_ArrayDisplay($days)

This script automatically downloads the file, saves it in the temporary files, and then extracts the following details from it, and puts in an array.

$days[x][y]

where x is the day, 0 is the current day, and 7 is the last day of the 8-day forecast.

y1 is the date

y2-4 is daytime

y2 is the image

y3 is the temperature

y4 is the comment

y5-7 is nighttime

y5 is the image

y6 is the temperature

y7 is the comment

If you want me to output this in a html file where I replace the image with the image you want, just tell me which image I should replace with which image..

Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

#include <array.au3>
InetGet("http://images.news8austin.com/media/xml/8dayforecast.xml", @TempDir & "Wheather.xml", 1)
$xml = FileRead(@TempDir & "wheather.xml")
$xml = StringSplit($xml, "<weatherdata>", 1)
_ArrayDelete($xml, 0)
_ArrayDelete($xml, 0)
Dim $days[8][7]

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "date>", 1)
    $days[$i][0] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "image>", 1)
    $days[$i][1] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "temperature>", 1)
    $days[$i][2] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "comment>", 1)
    $days[$i][3] = StringTrimRight($insert[2], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "image>", 1)
    $days[$i][4] = StringTrimRight($insert[4], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "temperature>", 1)
    $days[$i][5] = StringTrimRight($insert[4], 2)
Next

For $i = 0 To 7
    $insert = StringSplit($xml[$i], "comment>", 1)
    $days[$i][6] = StringTrimRight($insert[4], 2)
Next
_ArrayDisplay($days)

This script automatically downloads the file, saves it in the temporary files, and then extracts the following details from it, and puts in an array.

$days[x][y]

where x is the day, 0 is the current day, and 7 is the last day of the 8-day forecast.

y1 is the date

y2-4 is daytime

y2 is the image

y3 is the temperature

y4 is the comment

y5-7 is nighttime

y5 is the image

y6 is the temperature

y7 is the comment

If you want me to output this in a html file where I replace the image with the image you want, just tell me which image I should replace with which image..

I refuse to allow you to do all of the work, I want to learn! I will be studying this code now and attempting to understand why and how. I will send you a PM of the finished program, though. As well as, post it on here for avid searchers to use as a reference.

Share this post


Link to post
Share on other sites

the code is fairly simple. shouldn't be that hard to understand. If you PM me an msn address I'll add you and help you any further or not if you don't want me to. Either way, if you have an msn address, PM it, I'm interested in this project.


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0