Use ASP and Microsoft. xmldom to analyze remote XML files

Source: Internet
Author: User

Use the xmldom method to open the XML file. If the file is local, the server is used. mappath ("XML. XML ") method, the content can be analyzed normally, but the XML content is not displayed directly with the URL (the URL method is supported in xmldom ), later, I found that the XML can be obtained using XMLHTTP and then analyzed. The Code is 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. 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 content of the XML. XML document is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Channel>
<Item>
<Title> test document 1 </title>
<Link> http: // localhost/</link>
</Item>
<Item>
<Title> test document 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.