Gunit2507
asked on
Obtain XML Values
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>
ASKER
default:entry/default:titl e works
Thanks
Thanks
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.
"default:title" as the XPath query.
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.
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