Reading from XML

S

Simon Harris

Hi All,

Ok, this must be a simple one, I'm trying to read a certain elements
contents from an XML file. Heres what I've come up with so far, which
seems
to get stuick in a loop (ASPNET.EXE hogs the CPU until I kill it!)

Public Function GetPageName(ByVal XMLFileName As String) As String
Dim XmlReader As New
XmlTextReader(Session("DataLocation").ToString
& XMLFileName)

XmlReader.Read()
While Not XmlReader.EOF
If XmlReader.Name = "Title" Then
Return XmlReader.ReadString()
End If
End While

'Return XmlReader.ReadElementString("Title")
XmlReader.Close()
End Function


Note that session("datalocation") is a full path.

Thanks,
Simon.
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

XmlReader.Read()
While Not XmlReader.EOF
If XmlReader.Name = "Title" Then
Return XmlReader.ReadString()
End If
End While

This is endless loop. It is normal ASP.NET to crash what are u trying to do?
try to XPathNavigator or something like it.
 
B

bchandley

You need to move to the next elmennt using the read method. the code
you have is always reading the same node.

Try:

While XmlReader.Read()
If XmlReader.Name = "Title" Then
Return XmlReader.ReadString()
End If

End While
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,272
Latest member
MaricruzDu

Latest Threads

Top