Solved

VB.NET routines to parse XML data from NOAA

Posted on 2013-12-04
10
680 Views
Last Modified: 2013-12-12
Can someone please tell me how I can parse this data. I need to save it to a database but I just need the values but I am having difficulty. I am doing this in VB.NET and I need to be able to parse it through VB.NET.  I have attached the XML file I need to parse....

PLEASE HELP ME!!!
Weather.xml
0
Comment
Question by:jknj72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 39696625
Which version of .Net are you using?  The best approach for parsing XML is different depending on what features you have available to you.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39696638
Hi jknj72;

Exactly which nodes and values do you wish to parse from the XML document you have uploaded? Please be specific, thank you.
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39696675
You can use a dataset and its readxml method
Dim ds As New DataSet
ds.ReadXml

the dataset will create tables that you can review to determine the column names/indices that you need to grab.

There are going to be lots of different ways to consume XML so the best choice will be highly dependent on your scenario.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:jknj72
ID: 39696679
I am using VB.NET 2010

I am looking to get pretty much everything below the </head> but I really dont need the location since I have those values saved.
What I REALLY need is the time-layouts with the applicable key values and descriptions and ALL the parameter values.
If you have ANY other questions I will keep checking in and I will answer anything you need(if I can of course) ;)

THANK YOU SO MUCH FOR YOUR HELP!!!
0
 

Author Comment

by:jknj72
ID: 39696680
fyi, I am doing this in a VB.NET Console app to be scheduled to run periodically throughout the day
0
 

Author Comment

by:jknj72
ID: 39698498
Any thoughts???
0
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 39699412
Something like this would work:

XmlDocument xmlDoc= new XmlDocument();
xmlDoc.Load("Weather.xml");
XmlNodeList timeLayouts = xmlDoc.GetElementsByTagName("time-layout");
0
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 39699476
Sorry, I just realized that you are using VB, but your code should be very similar with some minor syntax differences.  The Class names will be the exact same.    

The XmlNodeList above is a list of XmlNodes.  Each XmlNode has a Name property that tells you which element it is. There is an Attributes property that contains zero or more XmlAttribute object.  Each XmlAttribute object has a name and a value.  The XmlNode object also has the ChildNodes property which contains the children which are also XmlNode objects.  

This approach is very solid although it does require coding to match the document.  As previously mentioned there are many different ways to do this depending on your situation but this is one tried-and-true way to do it.      

In my experience, the easiest way to code this approach is to have a separate method for each element name.  The method would accept an XmlNode object.  Each method would have 2 Select Case statements:  one inside an attribute loop and another inside a child node loop.  Inside the child node loop the select case would call the appropriate method based on the node name, passing in the current XmlNode object.

If you try this and run into trouble, just post back with the specific problem you are having.
0
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 500 total points
ID: 39699519
I should also mention that the text inside an element is also considered a child node.  So inside the child node loop you check the class of the node.  If the XmlNode is an object of XmlElement class then it is a regular child node, otherwise it represents the text of the element and you can use the Value property to get that text.  

So for example, looking at the following element:  

<start-valid-time period-name="Tonight">2013-12-03T18:00:00-06:00</start-valid-time>

You would have a method to process any XmlNode that has a name of "start-valid-time".  Inside that method, you would loop over the attributes and pick out value of the "period-name" which in this case would be "Tonight".  In the same method you would loop over the child nodes.  In this case there would only be one child node and it has a value of "2013-12-03T18:00:00-06:00".
0
 

Author Closing Comment

by:jknj72
ID: 39715118
thanks
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IDE for Python 5 73
vb.net datagrid scroll automatically to the first found row 11 28
asp.net repeater 2 17
aspx ascx, c# 7 20
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question