Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 131,682 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,493 people online right now. Registration is fast and FREE... Join Now!




Plz help // Reading and outputting Weather.com XML

 
Reply to this topicStart new topic

Plz help // Reading and outputting Weather.com XML, vb.net/asp.net

munchkin
post 10 May, 2005 - 03:24 AM
Post #1


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


hey all,

I have this lovely feed from weather.com and i can read the information in vb and output it with afew problems..

when i ask for the content of 't' (meaning cc.t) it reads through the document and outputs the last 't' (meaning cc.moon.t).

I know this seems abit vauge.. but i cant really be anymore specific at this time..

how would i select the correct node and read its value? cause at the moment i am using case to select 't' and i know that there is a better way....

Wether.com XML feed:
CODE

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--This document is intended only for use by authorized licensees of The Weather Channel. Unauthorized use is prohibited. Copyright 1995-2004, The Weather Channel Enterprises, Inc. All Rights Reserved.-->
<weather ver="2.0">
 <head>
   <locale>en_US</locale>
   <form>MEDIUM</form>
   <ut>C</ut>
   <ud>km</ud>
   <us>km/h</us>
   <up>mb</up>
   <ur>mm</ur>
 </head>
 <loc id="UKXX0092">
   <dnam>Manchester, United Kingdom</dnam>
   <tm>11:02 AM</tm>
   <lat>53.37</lat>
   <lon>-2.26</lon>
   <sunr>5:18 AM</sunr>
   <suns>8:54 PM</suns>
   <zone>1</zone>
 </loc>
 <cc>
   <lsup>5/10/05 10:20 AM Local Time</lsup>
   <obst>Manchester, United Kingdom</obst>
   <tmp>10</tmp>
   <flik>8</flik>
   <t>Partly Cloudy</t>
   <icon>30</icon>
   <bar>
     <r>1,023.0</r>
     <d>steady</d>
   </bar>
   <wind>
     <s>14</s>
     <gust>N/A</gust>
     <d>350</d>
     <t>N</t>
   </wind>
   <hmid>58</hmid>
   <vis>10.0</vis>
   <uv>
     <i>3</i>
     <t>Moderate</t>
   </uv>
   <dewp>2</dewp>
   <moon>
     <icon>1</icon>
     <t>Waxing Crescent</t>
   </moon>
 </cc>
</weather>



VB code:
CODE

While myReader.Read()
 If myReader.NodeType = XmlNodeType.Element Then
   Select Case myReader.Name
     Case "t"
       Me.description = myReader.ReadElementString
   end select
 end if
end while



Any help would be amazing.
User is offlineProfile CardPM

Go to the top of the page


zakary
post 10 May, 2005 - 06:25 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 400



Thanked 6 times

Dream Kudos: 175
My Contributions


<cc>
<t>Partly Cloudy</t>
<t>N</t>
<t>Moderate</t>
<t>Waxing Crescent</t>
</cc>

I am not completely sure but I think this is the problem. You have 4 t values all under cc their for the code will only return the last value.
User is offlineProfile CardPM

Go to the top of the page

munchkin
post 11 May, 2005 - 03:18 AM
Post #3


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


Yeah thats the problem - but hte xml is none - changeable as its a stream from weather.com :S

CODE


myXmlNodeReader = New XmlNodeReader(myWeatherDoc.SelectSingleNode("weather/cc[1]/tmp[1]"))

      While (myXmlNodeReader.Read())
          Select Case myXmlNodeReader.NodeType

              Case XmlNodeType.Element
                  Me.temperature = myXmlNodeReader.ReadElementString
          End Select
      End While



thats how ive figured it out so far - but there has to be a simpler way that having to do that for every value that needs to be returned...
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 11 May, 2005 - 06:28 AM
Post #4


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,124



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


I havent done VB in quite some time, but i am pretty sure it allows for dynamic memory allocation easilyish.


If you know how a tree works, then you may consider parseing the xml feed into a tree, because that is any XML document's logical structure.

Then maybe a depth-first serach for "t" data would yeild all results. Also the whole program would be much more robust.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 07:51AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month