Robb Hill
asked on
How do I capture the following XML using XmlDocument
I am trying to display the "title" and "description" tags out of this xml and cannot seem to code this correctly in vb.net....please help
Here is the xml and my code so far:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-styl esheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><!-- This is a data file meant to be read by an RSS reader. See http://www.wnbc.com/rss/index.html for more information. --><rss xmlns:ibsys="http://www.ibsys.com/rss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
<ibsys:annotation>This is a data file meant to be read by an RSS reader. See http://www.wnbc.com/rss/index.html for more information.</ibsys:annota tion>
<title>wnbc.com - Sports</title>
<description>Sports</descr iption>
<category>Sports</category >
<link>http://www.wnbc.com/sports/index.html?rss=ny&psp=sports</link>
<language>en-us</language>
<copyright>Copyright 2007, Portions © 2007 Internet Broadcasting Systems, Inc.</copyright>
<itunes:summary>Sports</it unes:summa ry>
<itunes:author>wnbc.com</i tunes:auth or>
<itunes:category text="Sports" />
<ttl>60</ttl>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/wnbc/sports" type="application/rss+xml" /><feedburner:browserFrien dly></feed burner:bro wserFriend ly><item>
<title>Rockies Rally In 13th Eliminates Padres</title>
<link>http://www.wnbc.com/sports/14243440/detail.html?rss=ny&psp=sports</link>
<ibsys:hasThumbnail>true</ ibsys:hasT humbnail>
<ibsys:associatedimage>http://www.wnbc.com/2007/1002/14249091.jpg</i bsys:assoc iatedimage >
<description>The Rockies beat the Padres, 9-8, Monday and advance to play Philadelphia in the first round in a series that starts Wednesday in Philadelphia.</description >
<pubDate>Tue, 2 Oct 2007 03:34:20 EDT</pubDate>
</item>
<item>
<title>48 Of Vick's Dogs Can Be Adopted</title>
<link>http://www.wnbc.com/sports/14249055/detail.html?rss=ny&psp=sports</link>
<description>Nearly all the dogs seized from Michael Vick's property in Virginia can be saved.</description>
<pubDate>Tue, 2 Oct 2007 02:31:46 EDT</pubDate>
</item>
Public Class form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrab.Click
Dim xmldoc As New XmlDocument
Dim xmlnlist As XmlNodeList
Dim xmln As XmlNode
Try
Dim strURL As String = "http://feeds.feedburner.com/wnbc/sports"
xmldoc.Load(strURL)
xmlnlist = xmldoc.SelectNodes("/item/ title")
For Each xmln In xmlnlist
Dim title = xmln.ChildNodes.Item(0).In nerText
Dim description = xmln.ChildNodes.Item(1).In nerText
Next
Catch ex As Exception
Console.WriteLine(ex.Messa ge)
End Try
End Sub
End Class
Here is the xml and my code so far:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-styl
<channel>
<ibsys:annotation>This is a data file meant to be read by an RSS reader. See http://www.wnbc.com/rss/index.html for more information.</ibsys:annota
<title>wnbc.com - Sports</title>
<description>Sports</descr
<category>Sports</category
<link>http://www.wnbc.com/sports/index.html?rss=ny&psp=sports</link>
<language>en-us</language>
<copyright>Copyright 2007, Portions © 2007 Internet Broadcasting Systems, Inc.</copyright>
<itunes:summary>Sports</it
<itunes:author>wnbc.com</i
<itunes:category text="Sports" />
<ttl>60</ttl>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/wnbc/sports" type="application/rss+xml"
<title>Rockies Rally In 13th Eliminates Padres</title>
<link>http://www.wnbc.com/sports/14243440/detail.html?rss=ny&psp=sports</link>
<ibsys:hasThumbnail>true</
<ibsys:associatedimage>http://www.wnbc.com/2007/1002/14249091.jpg</i
<description>The Rockies beat the Padres, 9-8, Monday and advance to play Philadelphia in the first round in a series that starts Wednesday in Philadelphia.</description
<pubDate>Tue, 2 Oct 2007 03:34:20 EDT</pubDate>
</item>
<item>
<title>48 Of Vick's Dogs Can Be Adopted</title>
<link>http://www.wnbc.com/sports/14249055/detail.html?rss=ny&psp=sports</link>
<description>Nearly all the dogs seized from Michael Vick's property in Virginia can be saved.</description>
<pubDate>Tue, 2 Oct 2007 02:31:46 EDT</pubDate>
</item>
Public Class form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrab.Click
Dim xmldoc As New XmlDocument
Dim xmlnlist As XmlNodeList
Dim xmln As XmlNode
Try
Dim strURL As String = "http://feeds.feedburner.com/wnbc/sports"
xmldoc.Load(strURL)
xmlnlist = xmldoc.SelectNodes("/item/
For Each xmln In xmlnlist
Dim title = xmln.ChildNodes.Item(0).In
Dim description = xmln.ChildNodes.Item(1).In
Next
Catch ex As Exception
Console.WriteLine(ex.Messa
End Try
End Sub
End Class
also to read xml from url you'll need xml reader
actually it should be xmlnlist = xmldoc.SelectNodes("//item ")
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks for the quick and good answer...
Do you mind explaining how you determined the child nodes were 0 and 4. There seemed to be some garbage in the xml...made it confusing fo rme to see the pattern
Do you mind explaining how you determined the child nodes were 0 and 4. There seemed to be some garbage in the xml...made it confusing fo rme to see the pattern
I opened xml file through the web and counted the chil nodes in <item> node. The "description" node was the 5th node, i.e. subscript 4. And "title" was the first child node, i.e. 0
ASKER
You are the man..thanks!
actually I am the woman:)
ASKER
I had a feeling after I posted you would say that....hehe.
Thanks again!!
Thanks again!!
xmlnlist = xmldoc.SelectNodes("/item/
to
xmlnlist = xmldoc.SelectNodes("//item