Problem loading XML

Y

YYZ

Hi guys. When I receive an XML string via the net (HttpWebResponse), 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.LoadXML(sResponse) <-- error here -- "An unhandled
exception of type 'System.Xml.XmlException' 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>SUCCESS</StatusCode>
<StatusMessage></StatusMessage>
<TransactionID>66d4bf32-22c8-46c1-9248-80fe280e733e</TransactionID>
<ClientOrderID>060283000009-1</ClientOrderID>
<ClientLineItemID></ClientLineItemID>
<ReceivedDateTime>2006/24/05</ReceivedDateTime>
</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
 
C

Chris Dunaway

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.InnerException
End While

End Try

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

YYZ

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
 

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

Top