Solved

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

Posted on 2009-06-27
4
1,103 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert image with its metadata into SQL server Database 3 90
Iterate two lists and remove inactive 11 49
Syntax error 9 45
Anyway to make "All" the default in the dropdown? 6 34
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now