Solved

"Cannot have a DOCTYPE declaration outside of a prolog" on LoadXML in VB Macro

Posted on 2009-06-27
4
1,116 Views
Last Modified: 2013-12-17
I've been searching for several hours for this and decided to post my first post here.  I have an Excel Macro written in VB that is calling a WebService (written in ASP.net/C#).  The WebService then returns an XML string to Excel.  When the macro does a "LoadXML()" .. i get the "Cannot have a DOCTYPE declaration outside of a prolog."

I ran the XML string through a validator to make sure it was well-formed and it is.  This is a snippit of the XML returned to Excel (it's a pretty long string):

XML
--------------
<risk><result>true</result><message />
<currentdata>
<mydata><id>20531</id></mydata> ...
</currentdata>
</risk>

VB:
--------------------------------
Dim oMessageXML As New MSXML2.DOMDocument

oMessageXML.async = False
oMessageXML.LoadXml (xmlMessage)
If (oMessageXML.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = oMessageXML.parseError
   MsgBox ("You have error " & myErr.reason & " ErrCode: " & myErr.errorCode)
End If
 ....


Any assistance will be greatly appreciated!!

The XML sent has a format that I then use to build another XML string.  I'm not displaying this.  I just need to read it so I can work with it.

This process used to use an Oracle DB and I am converting it to use SQL Server 2008.  Also the project was initially in VS 2005 and I'm now running it in VS 2008 (for ASP.net).  In the old instance of the project, the XML string sent back looks identical to the one I am receiving in this case.

0
Comment
Question by:burtj
  • 3
4 Comments
 

Author Comment

by:burtj
ID: 24731212
Here's an interesting note ... if I hardcode part of the XML string, it gets past the check.  I hardcoded this .. the actual XML string is really long:

<risk><result>true</result><message /><currdata><sr><srid>20531</srid><ldid>321484</ldid><pricing>2</pricing><proposaldate>1/16/2009 12:00:00 AM</proposaldate><requestdate>12/12/2008 12:00:00 AM</requestdate><comments></comments><createname>HOPE, WILLEM</createname><createdate>12/12/2008 12:00:00 AM</createdate><mdfyname>MOUSE, MICKEY</mdfyname><mdfydate>12/15/2008 12:00:00 AM</mdfydate></sr></currdata><employee><employeecode>81955</employeecode><employeename>FOX, FRED</employeename><ntid>fredfox</ntid></employee><opp><ldid>321484</ldid><lname>Media Business Manage </lname><companyname>CompName, Inc.</companyname></opp></risk>
0
 

Author Comment

by:burtj
ID: 24731227
Is it possible that my XML String is too long?  I just checked ... it has 17592 characters.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 225 total points
ID: 24732246
No the string is not too long.  The problem is that the asp.net web service is returning more than just XML.  The solution will lie in the code for the web service.  It sounds like it's returning HTML along with the XML, which might mean that you are accessing an ASP.NET webform instead of a web service.

If you are using an ASPX page to return the XML, you have to ensure that you do not have any declared HTML (only the page declaration is required.)  See link for example

http://www.deez.info/sengelha/2006/02/06/how-return-xml-from-aspx-in-aspnet-11/
0
 

Author Comment

by:burtj
ID: 24732558
Paul ... you got it!  In my .aspx file, it had a doctype definition and other HTML ... once I removed that and only left the @Page definition, it worked!  Thank you!!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question