Considerations for using Msxml2.domdocument to process XML data in ASP application techniques

Source: Internet
Author: User
Tags xml attribute

When ASP uses msxml2.domdocument to load XML files on the network, you need to be aware of the settings before calling the Load method:

Copy Code code as follows:

Oxml.setproperty "ServerHTTPRequest", True

The ServerHTTPRequest request is enabled, and no system error occurs:-2146697209.

The ASP needs to be aware of the 4 situation when using the Msxml2.domdocument component

Copy Code code as follows:

<%
Dim oXML, Oxmlerror, returnvalue, X
Set oXML = Server.CreateObject ("MSXML2. DOMDocument ")
' Set DOMDocument to load an XML file asynchronously or synchronously
Oxml.async = False ' ==========a
' Set purpose: True/false to indicate whether to load an XML document using the ServerXMLHTTP component of server security
Oxml.setproperty "ServerHTTPRequest", True ' ==========b
' Load network XML file via HTTP
returnvalue = Oxml.load ("Http://localhost/asp/ServerXML.xml") ' ==========c
' or load the server local XML file
' ReturnValue = Oxml.load ("D:\test.xml") ' ==========d

' Hit the Domdocument.load return value:
Response.Write "Result to load method is =" & ReturnValue & "<br>"
%>

In the first case (loading an empty document):

By default, the Async property of the DOMDocument object is true, that is, it is loaded asynchronously. And the ServerXMLHTTP component is not used when loading. That is, the line A and B lines of code in the above code are commented out.

Copy Code code as follows:

' Oxml.async = False ' ==========a
' Oxml.setproperty ' serverhttprequest ', true ' ==========b

At this point, the load will succeed. ReturnValue will be true. However, the XML document loaded into DOMDocument is empty! In other words, the Load method returns True as a cover! The results are as follows: In this case, programmers must be careful! Although XML does not report any errors, and the Load method also indicates success, the XML attribute of the DOM is empty.

The second case (the reason for the error is:-2146697209):

If you explicitly declare that the Async property is False, the XML document is loaded synchronously. And the ServerXMLHTTP component is not used when loading. That is, only the line B code in the above code is commented out.

Copy Code code as follows:

Oxml.async = False ' ==========a
' Oxml.setproperty ' serverhttprequest ', true ' ==========b

Then there will be failure! ReturnValue will be false. The reason for the error is:-2146697209-No available data for the required resource. In other words, it is not successful to load XML resources on the Internet synchronously!!

Third case (not allowed):

If your async property is true, the XML document is loaded asynchronously. And the ServerXMLHTTP component is used when loading. The line B code in the above code is enabled. Comment out line a code.

Copy Code code as follows:

' Oxml.async = False ' ==========a
Oxml.setproperty "ServerHTTPRequest", True ' ==========b

Reported an error! Description using the SXH component to load an XML document asynchronously is not allowed! The error is described as: -1072897486-the serverhttprequest property can, used when loading a document asynchronously and are only SUP Ported on Windows NT 4.0 and above.

case Fourth (correct use):

If you explicitly declare that the Async property is False, the XML document is loaded synchronously. And the ServerXMLHTTP component is used when loading. The first and B lines of code in the above code are enabled.

Copy Code code as follows:

Oxml.async = False ' ==========a
Oxml.setproperty "ServerHTTPRequest", True ' ==========b

That'll be all! Explains that using the SXH component to load an XML document corrects the error of asynchronously loading Internet resources.

Summarize

serverxmlhttp components

asynchronous load load will succeed. However, the XML document loaded into DOMDocument is empty
sync load do not use the will encounter failure! The reason for the error is:-2146697209-No available data for the required resource.
asynchronous loading use
synchronous loading true success
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.