?
Solved

How do I capture the following XML using XmlDocument

Posted on 2007-10-02
9
Medium Priority
?
418 Views
Last Modified: 2012-06-27
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


0
Comment
Question by:Robb Hill
  • 6
  • 3
9 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 19999521
change

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

to

xmlnlist = xmldoc.SelectNodes("//item/title")
0
 
LVL 35

Expert Comment

by:YZlat
ID: 19999615
also to read xml from url you'll need xml reader
0
 
LVL 35

Expert Comment

by:YZlat
ID: 19999715
actually it should be xmlnlist = xmldoc.SelectNodes("//item")
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 19999730
Dim xmldoc As New Xml.XmlDocument
        Dim xmlnlist As Xml.XmlNodeList
        Dim xmln As Xml.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).InnerText
                Dim description = xmln.ChildNodes.Item(4).InnerText
            Next
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 19999990
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 20000451
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
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 20000595
You are the man..thanks!
0
 
LVL 35

Expert Comment

by:YZlat
ID: 20000684
actually I am the woman:)
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 20000706
I had a feeling after I posted you would say that....hehe.
Thanks again!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

750 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