Analysis of remote XML files using ASP and Microsoft.XMLDOM

Source: Internet
Author: User
Tags documentation
Dom|xml

Open the XML file with the Xmldom method, if the local is not a problem, is the use of Server.MapPath ("Xml.xml") method, then the normal analysis of the content, but the direct use of the URL does not show the XML content (in the XMLDOM representation is the support URL way) , and then studied the discovery that the XMLHTTP method can be used to obtain XML and then analyze the code as follows:

Set http=server.createobject ("Microsoft.XMLHTTP")
http. Open "Get", "Http://localhost/xml.xml", False
Http.send

Set xml=server.createobject ("Microsoft.XMLDOM")
Xml. Async=false
Xml. Validateonparse=false
Xml. Load (http. Responsexml)
If XML. Readystate>2 Then
Response.Write (the document is ready to go.) Status: "& XML. ReadyState & "<br>")
Set item=xml.getelementsbytagname ("item")
For I=0 to (item. LENGTH-1)
Set Title=item. Item (i). getElementsByTagName ("title")
Set Link=item. Item (i). getElementsByTagName ("link")
Response.Write ("<a href=" "" "& Link. Item (0). Text & "" > "& title. Item (0). Text & "</a><br>")
Next
Else
Response.Write ("The document is not ready yet.) Status: "& XML. ReadyState & "<br>")
End If
Set http=nothing
Set xml=nothing


The contents of the Xml.xml document are as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<channel>
<item>
<title> Test Documentation 1</title>
<link>http://localhost/</link>
</item>
<item>
<title> Test Documentation 2</title>
<link>http://localhostindex.asp</link>
</item>
</channel>



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.