Problem loading XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • YYZ

    #1

    Problem loading XML

    Hi guys. When I receive an XML string via the net (HttpWebRespons e), I
    can't load it into an Xml.XmlDocument object. However, if I take that
    exact same string of XML and load it up in another program, it works
    fine. Here's what I mean:

    sResponse has been received via the web and is immediately used like
    this:

    dim ParseResponse as Xml.XmlDocument

    ParseResponse.L oadXML(sRespons e) <-- error here -- "An unhandled
    exception of type 'System.Xml.Xml Exception' occurred in system.xml.dll"

    sResponse looks like this:
    <?xml version='1.0' encoding='UTF-8' ?>
    <ns0:LALSXML xmlns:ns0="http ://Client.LALS.Ack .Version1">
    <Status>SUCCESS </Status>
    <StatusCode>SUC CESS</StatusCode>
    <StatusMessage> </StatusMessage>
    <TransactionID> 66d4bf32-22c8-46c1-9248-80fe280e733e</TransactionID>
    <ClientOrderID> 060283000009-1</ClientOrderID>
    <ClientLineItem ID></ClientLineItemI D>
    <ReceivedDateTi me>2006/24/05</ReceivedDateTim e>
    </ns0:LALSXML>

    If I put that XML into a string variable in another program and then
    load it up the same way into an XMLDocument object, it loads fine and I
    can start enumerating nodes.

    Can anyone point me in a likely direction for a solution here? What
    might I be doing wrong?

    Matt

  • Chris Dunaway

    #2
    Re: Problem loading XML

    Put a try catch around the code and recursively examine all the
    exceptions that might be included. Often, the inner exceptions will
    tell why it is bombinb. I use code similar to this:

    Try
    'code
    Catch Ex As Exception
    Dim s As String

    While Not Ex Is Nothing
    s &= Ex.Message & ": " & Ex.StackTrace & vbCrLf
    Ex = Ex.InnerExcepti on
    End While

    End Try

    Perhaps this will give you more information on what the problem is.

    Comment

    • YYZ

      #3
      Re: Problem loading XML

      I had no idea that catching exceptions would tell you more than just
      examining the error as it happened in the debugger. Thanks for that.
      I can't believe I didn't know that.

      The error turns out that an XML doc (to work with the MS parser, at
      least) must not include ANY whitespace at all before the first line.
      There's an hour and a half I'll never get back.

      Thanks for the pointer. That actually will assuredly help me out in
      tons of other situations where I was getting a really vague error.

      Matt

      Comment

      Working...