XML parse error: Invalid at the top level of the document

2,576 views
Skip to first unread message

Nebulus

unread,
Jun 5, 2007, 12:47:03 PM6/5/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hey all. Ok, I've got some code that consumes a web service from a
vendor of ours, and I'm having issues with the returned data. When I
do receive the response, the XMLDOM object is throwing a parse error:
Invalid at the top level of the document. I'm not sure what's going on
since this is valid SOAP formatted XML. Here's a snippet of the
returned XML:

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:insuranceauthorityResponse soapenv:encodingStyle="http://
schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://
DefaultNamespace">
<insuranceauthorityReturn xsi:type="ns2:Map" xmlns:ns2="http://
xml.apache.org/xml-soap">
<item xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="soapenc:string">MC546717</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="soapenc:string">FMCSAAPPLICANTID</key>
<value xsi:type="soapenc:string">460907</value>
</item>
<item>
<key xsi:type="soapenc:string">CENSUSCLASSDEF</key>
<value xsi:type="soapenc:string"></value>
</item>
</value>
</item>
</insuranceauthorityReturn>
</ns1:insuranceauthorityResponse>
</soapenv:Body>
</soapenv:Envelope>

Any ideas as to why this fails on a parse? Any help is appreciated!

Nebulus

unread,
Jun 6, 2007, 3:32:47 PM6/6/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
^bump^ Anybody???

Smith, Peter

unread,
Jun 7, 2007, 10:13:29 AM6/7/07
to DotNetDe...@googlegroups.com
scripsit Nebulus

> When I do receive the response, the XMLDOM object is throwing a
> parse error:
> Invalid at the top level of the document.
> I'm not sure what's going on since this is valid SOAP formatted XML.

caveat: SOAP isn't my cup of tea. :)

For anyone looking at this, here's what I've tried:

- loads fine into XML Notepad
- Views fine in IE 7, no idea which DOM model version it might be using.
:)

http://www.xml.com/2000/05/10/conformance/reports/msxml3-nv.html says
that this error occurs (successfully) in their testing for the following
reasons:

- Text may not appear after the root element.
- Character references may not appear after the root element.
- Provides #PCDATA text after the document element.
- Provides a CDATA section after the root element.
- CDATA is invalid at top level of document.
- Invalid character reference.
- Invalid placement of CDATA section.
- Invalid placement of entity declaration.
- Tags invalid within EntityDecl.
- Entity reference must be in content of element.
- Invalid placement of Parameter entity reference.
- Use of illegal character within XML document. (multiple tests)
- References aren't allowed in Misc, even if they would resolve to valid
Misc.

Maybe these will help. If you go to that site, you can look up the tests
and see what they actually are. :)

Lessee, what else can I find in this 15 minutes of break time....

From http://support.microsoft.com/default.aspx?scid=kb;EN-US;q251134 :
SYMPTOMS
When attempting to load an XML file saved as UTF-7 (a transfer encoding
format for Unicode), the XML parser in Internet Explorer generates the
following error message:

Invalid at the top level of the document.

The same error also occurs when using the MSXML parser from server-side
or client-side script.


Oh, look, hit #6, OP's message.... :)

http://msdn2.microsoft.com/en-us/library/ms762632.aspx has something
about a ProhibitDTD property, which is true by default now, wasn't in
past versions.. Setting this property to true will prohibit DTDs and
result in a parse error of "Invalid at the top level of the document"
(XML_E_INVALIDATROOTLEVEL, 0xE52D) whenever a DTD is included.

And that's the end of my break. :) Back to you, Cerebrus.


_____
Peter Smith


Cerebrus

unread,
Jun 7, 2007, 11:37:00 AM6/7/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Awesome work, Peter ! That too in your break ! A pity SOAP isn't my
bar of surfactant too.

Nebulus

unread,
Jun 11, 2007, 10:12:08 AM6/11/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Peter,
Thanks very much for the nudge in the right direction, that'll really
help! I'm defintitely not a SOAP fan, especially when it gets as
verbose and bloated like the example I posted. I'm more of a JSON man
myself.

Anyway, that's again for the help!

Nebulus

unread,
Jun 11, 2007, 10:31:08 AM6/11/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Absolutely phenominal:

Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.setProperty "ProhibitDTD", True

This enables the XMLDom object for parsing SOAP. Thanks again for the
research!

> Fromhttp://support.microsoft.com/default.aspx?scid=kb;EN-US;q251134:


> SYMPTOMS
> When attempting to load an XML file saved as UTF-7 (a transfer encoding
> format for Unicode), the XML parser in Internet Explorer generates the
> following error message:
> Invalid at the top level of the document.
> The same error also occurs when using the MSXML parser from server-side
> or client-side script.
>
> Oh, look, hit #6, OP's message.... :)
>

> http://msdn2.microsoft.com/en-us/library/ms762632.aspxhas something

Reply all
Reply to author
Forward
0 new messages