Reading from XML

  • Thread starter Thread starter Simon Harris
  • Start date Start date
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.
 
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.
 
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
 
Back
Top