perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Thursday, 11 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: In my ASP page, I am loading the XML document from the Request stream. If the posted XML document contains a reference to an external DTD, the load fails and parseError reports No data is available for the requested resource. Please help.
Asked By: Erin
Viewed: 5349
Answer: In your ASP page, when you try to load the XML document from the Request stream, if the XML document contains reference to external DTD on some different remote server, the parser tries to resolve the external reference (to the DTD), but since you have not set the ServerHTTPRequest property, it fails to load the XML document.

Alternatively, you can set the resolveExternals property to False before loading the XML document.

Letís look at an example:

Here is a sample ASP page:
<%@ Language=VBScript %>
<%

   Dim objXMLDoc

   Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")

   'objXMLDoc.setProperty "ServerHTTPRequest", True
   
   objXMLDoc.validateOnParse = False

   'objXMLDoc.resolveExternals = False

   If objXMLDoc.load(Request) Then

      Response.Write "Top element has " & _
         objXMLDoc.documentElement.attributes.length & _
         " attribute(s)."
   Else
      Response.Write objXMLDoc.parseError.reason 
   End If

   Set objXMLDoc = Nothing
%>
The above ASP page uses MSXML 3.0 to load XML data from the request stream and if succeeds, returns the total number of attributes on the top element, else returns the parseError string.

Here is some sample Visual Basic 6.0 code that posts XML to the above ASP page. Note that the posted XML contains reference to DTD on some different remote server.
    Dim objXMLHTTP As New MSXML2.XMLHTTP30
    Dim xmlString As String

    xmlString = "<?xml version='1.0' encoding='utf-8'?> " & vbNewLine & _
        "<!DOCTYPE OrderList SYSTEM 'http://someremoteserver.com/test.dtd'>" & vbNewLine & _
        "<MyDoc id='1' loc='Chicago' />"

    objXMLHTTP.open "POST", "http://localhost/temp/CountAttributes.asp", False

    objXMLHTTP.send xmlString
    
    MsgBox objXMLHTTP.responseText
The above Visual Basic 6.0 code uses MSXML XMLHTTP class to post some XML text to previously discussed ASP page. If you run the code as it is, you'll see the error No data is available for the requested resource.; however, if you uncomment either of the lines in the ASP page, everything should work fine.


Go back to list of previously asked questions and answers
  Contact Us | E-mail Us | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy