tags:

views:

20

answers:

1

I'm trying to parse some XML (html) I downloaded using WebRequest.Create() and then read it. However after loading the XML file using LoadXml(string), anything else I execute doesn't work. Setting a breakpoint on anything afterwards doesn't work and it doesn't break.

I tried catching exception but none are occurring, so I'm not sure what the problem is.

Here is my code:

Dim reader As StreamReader = New StreamReader(HTTPResponse.GetResponseStream())
        Dim xDoc As XmlDocument = New XmlDocument()
        xDoc.LoadXml(reader.ReadToEnd())
        Dim omfg As String = xDoc.ChildNodes().Item(0).InnerText()
        Dim name As XmlNodeList = xDoc.GetElementsByTagName("div")
        Dim jj As Integer = name.Count
        For i As Integer = 0 To name.Count - 1
            MessageBox.Show(name.Item(i).InnerText)
        Next i

Anything after the "xDoc.LoadXml(reader.ReadToEnd())" doesn't execute.. Any ideas on this? My XML does have some whitespace at the beginning, I don't know if that is causing the problem...

+1  A: 

Just a guess, but it's throwing an exception because the html you download isn't well-formed xml, and you have a high-level try catch block hiding the error from you.

Joel Coehoorn
Hmm you're right. Is there any way I can find out whats wrong in the xml?
Bead
you should probably remove the try catch block, or debug.print the exception that is being caught. probably would shed some light on the issue at least
nathan gonzalez
@Bead - Unlike html, real xml is a very... picky format. Compliant xml parkers are supposed to treat anything not perfect as a fatal error. It can be very tricky to use an xml parser on a real world html document.
Joel Coehoorn