Avatar of jknj72
jknj72 asked on

VB.NET routines to parse XML data from NOAA

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
Visual Basic.NET.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
jknj72

8/22/2022 - Mon
MajorBigDeal

Which version of .Net are you using?  The best approach for parsing XML is different depending on what features you have available to you.
Fernando Soto

Hi jknj72;

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

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
jknj72

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!!!
ASKER
jknj72

fyi, I am doing this in a VB.NET Console app to be scheduled to run periodically throughout the day
ASKER
jknj72

Any thoughts???
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
MajorBigDeal

Something like this would work:

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

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.
ASKER CERTIFIED SOLUTION
MajorBigDeal

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
jknj72

thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61