ASP reads XML document instance code

Source: Internet
Author: User
Tags servervariables

<%
H=getlocationurl ()
H1=split (H, "/")
H=replace (H,H1 (UBound (H1)), "Note.xml")

Set http=server.createobject ("Microsoft.XMLHTTP")
http. Open "Get", H,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 & "" "target=" "_blank" ">" & 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

Function Getlocationurl ()
Dim URL
Dim serverport,servername,scriptname,querystring
ServerName = Request.ServerVariables ("SERVER_NAME")
ServerPort = Request.ServerVariables ("Server_port")
ScriptName = Request.ServerVariables ("Script_name")
QueryString = Request.ServerVariables ("query_string")
Url= "http://" &servername
If serverport <> "Then" url = URL & ":" & ServerPort
Url=url&scriptname
If querystring <> "" Then url=url& "?" & QueryString
Getlocationurl=url
End Function
' <?xml version= ' 1.0 ' encoding= ' gb2312 '?>
<channel>
<item>
<title> Sina </title>
<link>http://www.111cn.net Tutorials </link>
</item>
<item>
<title>google</title>
<link>http://www.111cn.net</link>
</item>
<item>
<title> Baidu </title>
<link>http://www.111cn.net</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.