Link to home
Create AccountLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

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-stylesheet 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:annotation>
<title>wnbc.com - Sports</title>
<description>Sports</description>
<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</itunes:summary>
<itunes:author>wnbc.com</itunes:author>
<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:browserFriendly></feedburner:browserFriendly><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:hasThumbnail>
<ibsys:associatedimage>http://www.wnbc.com/2007/1002/14249091.jpg</ibsys:associatedimage>
<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).InnerText
                Dim description = xmln.ChildNodes.Item(1).InnerText
            Next
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Class


Avatar of YZlat
YZlat
Flag of United States of America image

change

xmlnlist = xmldoc.SelectNodes("/item/title")

to

xmlnlist = xmldoc.SelectNodes("//item/title")
also to read xml from url you'll need xml reader
actually it should be xmlnlist = xmldoc.SelectNodes("//item")
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Robb Hill

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
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
You are the man..thanks!
actually I am the woman:)
I had a feeling after I posted you would say that....hehe.
Thanks again!!