[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.NET/VB: Loop through XML to get more than one result

Posted on 2013-12-17
3
Medium Priority
?
588 Views
Last Modified: 2013-12-17
This only returns the first URL.  I want all URLs to be returned.
<%@ Page Language="VB" %>
<%@Import namespace="System"%>
<%@Import namespace="System.Xml"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim XML As String
Using WC As New System.Net.WebClient()
 XML = WC.DownloadString("http://www.freesitemapgenerator.com/sitemap.xml")
End Using

Dim output As StringBuilder = New StringBuilder()

Using reader As XmlReader = XmlReader.Create(New StringReader(XML))
 reader.ReadToFollowing("url")
 reader.MoveToFirstAttribute()
 reader.ReadToFollowing("loc")
 output.AppendLine("<hr/>URL: " + reader.ReadElementContentAsString())
End Using

HttpContext.Current.Response.Write(output.ToString())

%>

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 39724559
Have you tried using

While reader.read()

loop?
0
 
LVL 16

Author Comment

by:hankknight
ID: 39724583
This gives an error:
<%@ Page Language="VB" %>
<%@Import namespace="System"%>
<%@Import namespace="System.Xml"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim XML As String
Using WC As New System.Net.WebClient()
 XML = WC.DownloadString("http://www.freesitemapgenerator.com/sitemap.xml")
End Using

Dim output As StringBuilder = New StringBuilder()

Using reader As XmlReader = XmlReader.Create(New StringReader(XML))
 While reader.read()
  reader.ReadToFollowing("url")
  reader.MoveToFirstAttribute()
  reader.ReadToFollowing("loc")
  output.AppendLine("<hr/>URL: " + reader.ReadElementContentAsString())
 End While
End Using

HttpContext.Current.Response.Write(output.ToString())

%>

Open in new window

The ReadElementContentAsString method is not supported on node type None. Line 1616, position 1.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 39724960
You need a loop along the lines of:
        While reader.ReadToFollowing("url")
            If reader.ReadToDescendant("loc") Then
                output.AppendLine("<hr/>URL: " + reader.ReadElementContentAsString())
            End If
        End While

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

656 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