当前位置:K88软件开发文章中心编程语言XmlXml01 → 文章内容

asp获取xml中的内容

减小字体 增大字体 作者:wangsdong     来源:asp编程网  发布时间:2018-12-30 9:25:55

note.xml中的内容
<
?xml 
version="
1.0"
 
encoding="
gb2312"
?>

<
channel>

<
item>

 
 
<
title>
新浪<
/title>

 
 
<
link>
http://www.sina.com.cn<
/link>

<
/item>

<
item>

 
 
<
title>
google<
/title>

 
 
<
link>
http://www.google.cn<
/link>

<
/item>

<
item>

 
 
<
title>
百度<
/title>

 
 
<
link>
http://www.baidu.com<
/link>

<
/item>

<
/channel>


index.asp中的内容
<
%
h=GetLocationURL()&
#39
获取当前地址
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>

Then
 
 
 
 
 
 
 
 
Response.Write("
文档已经准备就绪。状态:"
&

#38
 
xml.ReadyState 
&

#38
"

"
)
 
 
 
 
 
 
 
 
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("
<

href="
"
"
&

#38
 
link.Item(0).Text 
&

#38
"
"
"
 
target="
"
_blank"
"
>
"
&

#38
 
title.Item(0).Text 
&

#38
"
<
/a>

"
)
 
 
 
 
 
 
 
 
Next
Else
 
 
 
 
 
 
 
 
Response.Write("
文档还未准备就绪。状态:"
&

#38
 
xml.ReadyState 
&

#38
"

"
)
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://"
&

#38
ServerName 

If 
ServerPort 
<
>
 
"
80"
 
Then 
Url 

Url 
&

#38
 
"
:"
 
&

#38
 
ServerPort 

Url=Url&

#38
ScriptName 

If 
QueryString 
<
>
"
"
 
Then 
Url=Url&

#38
"
?"
&

#38
 
QueryString 

GetLocationURL=Url 

End 
Function 

%>

运行index.asp文件
源码地址:http://www.aspprogram.cn/soft.asp?id=19

asp获取xml中的内容