[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Obtain XML Values

Posted on 2009-04-27
6
Medium Priority
?
398 Views
Last Modified: 2012-05-06
Hello,

I am attempting to create a script in Vb.Net that opens the http://www.weather.gov/alerts-beta/wwaatmget.php?x=MTZ049 XML document and obtains the following information (Warning Title, Issued Time, and Expired Time).  Is this possible and how would I do this?  I have no XML experience at all...

Thanks
0
Comment
Question by:Gunit2507
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:ReinisB
ID: 24245031
The way i am doing it in my own code at the moment is this:

1. Obtain the XML file using the httpwebrequest and httpwebresponse methods to query the URL
2.  Save the incoming stream into a text file with the xml extension (the incoming stream is actually in xml format)
3. Use an XMLReader.Create construct to open an XMLReader with the file you just obtained as the source.  Then you can use the reader to move around the XML file node-by-node.

Information can be found here:

XML general http://www.w3schools.com/xml/default.asp
HttpWebRequest and WebResponse http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.71).aspx and http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse(VS.71).aspx
XMLReader http://msdn.microsoft.com/en-us/library/9d83k261.aspx
0
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24245103
The System.Xml.XmlDocument would be the way to go:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx
http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.aspx

You'll also want to read up on XPath:
http://www.w3schools.com/XPath/default.asp
Dim doc As New XmlDocument()
doc.Load("http://www.weather.gov/alerts-beta/wwaatmget.php?x=MTZ049")
Dim nsMgr As New XmlNamespaceManager(doc.NameTable)
nsMgr.AddNamespace("default", "http://www.w3.org/2005/Atom")
nsMgr.AddNamespace("cap", "urn:oasis:names:tc:emergency:cap:1.1")
Dim node As XmlNode
 
' Updated date
node = doc.DocumentElement.SelectSingleNode("default:entry/default:updated", nsMgr)
Dim updated As DateTime = DateTime.Parse(node.InnerText)
 
' Area Desc
node = doc.DocumentElement.SelectSingleNode("default:entry/cap:areaDesc", nsMgr)
Dim areaDesc As String = node.InnerText

Open in new window

0
 

Author Comment

by:Gunit2507
ID: 24245488
Instead of area desc I am attempting to get title, although it's not working... I am trying "default:entry/title"
<?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?>
<?xml-stylesheet href='capatom.xsl' type='text/xsl'?>
 
<!--
this comment is here to foil Internet Explorer and Firefox attempt to treat
this as a channel and thereby ignore our stylesheet
this comment is here to foil Internet Explorer and Firefox attempt to treat
this as a channel and thereby ignore our stylesheet
this comment is here to foil Internet Explorer and Firefox attempt to treat
this as a channel and thereby ignore our stylesheet
-->
<feed xmlns = 'http://www.w3.org/2005/Atom'
xmlns:cap = 'urn:oasis:names:tc:emergency:cap:1.1'
xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'>
 
  <id>http://www.weather.gov/alerts-beta/wwaatmget.php?x=MTZ049</id>
  <generator>
  NWS CAP Server
  </generator>
  <updated>2009-04-27T16:35:33-04:00</updated>
  <author>
  <name>
  w-nws.webmaster@noaa.gov
  </name>
  </author>
  <title>
  Current Watches, Warnings and Advisories for Eastern Teton (MTZ049) Montana Issued by the National Weather Service
  </title>
  <link href='http://www.weather.gov/alerts-beta/wwaatmget.php?x=MTZ049'/>
<entry>
<id>http://www.weather.gov/alerts-beta/wwacapget.php?x=MT20090427114000TFXWinterStormWarningTFX20090430120000MT</id>
<updated>2009-04-27T16:35:33-04:00</updated>
<author>
<name>
w-nws.webmaster@noaa.gov
</name>
</author>
<title>
Winter Storm Warning issued April 27, 2009 at 5:40AM MDT expiring April 30, 2009 at 6:00AM MDT
Issued by Weather Forecast Office GreatFalls http://www.wrh.noaa.gov/Greatfalls/
</title>
<link href="http://www.weather.gov/alerts-beta/wwacapget.php?x=MT20090427114000TFXWinterStormWarningTFX20090430120000MT"/>
<summary>
...MAJOR SPRING STORM TO IMPACT MONTANA THIS WEEK....A STRONG SPRING STORM WILL IMPACT ALL OF MONTANA THIS WEEK. ALOW PRESSURE SYSTEM WILL DEEPEN ALONG THE PACIFIC NORTHWEST COASTTODAY AND TONIGHT...THEN IT WILL MOVE INLAND AND STALL OUT OVERTHE REGION...BRINGING ABUNDANT PRECIPITATION AND COOLERTEMPERATURES THROUGH MOST OF THE WEEK.
</summary>
<cap:effective>
2009-04-27T05:40:00-06:00
</cap:effective>
<cap:expires>
2009-04-30T06:00:00-06:00
</cap:expires>
<cap:status>
Actual
</cap:status>
<cap:msgType>
Alert
</cap:msgType>
<cap:category>
Met
</cap:category>
<cap:urgency>
Expected
</cap:urgency>
<cap:severity>
Moderate
</cap:severity>
<cap:certainty>
Likely
</cap:certainty>
<cap:areaDesc>
Northern Rocky Mountain Front; Eastern Glacier; Hill; Cascade; Chouteau; Central, Southern Lewis, C; Toole; Liberty; Eastern Pondera; Blaine; Southern Rocky Mountain Front; Eastern Teton; Judith Basin; Fergus
</cap:areaDesc>
</entry>
</feed>

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:Gunit2507
ID: 24245585
default:entry/default:title works
Thanks
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24245589
If you notice, title isn't a child element of entry. Also, for any elements that don't have a prefix (ie. title vs. cap:areaDesc), you need use the prefix default. Hence, you would use
"default:title" as the XPath query.
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24245604
Just posted after you accepted the answer, my previous post was for the 1st title element, rather than the one in the entry element. But already had worked it out.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Native ability to set a user account password via AD GPO was removed because the passwords can be easily decrypted by any authenticated user in the domain. Microsoft recommends LAPS as a replacement and I have written an article that does something …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

612 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