网络编程
位置:首页>> 网络编程>> XML编程>> ASP怎么读取指定xml 的节点

ASP怎么读取指定xml 的节点

 来源:无忧脚本 发布时间:2008-04-28 13:12:00 

标签:节点,xml,asp

zyw147 提出问题:ASP读取指定xml 的节点?

怎么用ASP《不是JS》取出指定的节点? 例如我想取出北京,我在ASP客户端提交的是 1 ,怎么用1取北京?

<?xml version="1.0" encoding="gb2312"?> 
<data> 
<book> 
<cost>1</cost> 
<name>北京</name> 
</book> 
<book> 
<cost>2</cost> 
<name>上海</name> 
</book> 
<book> 
<cost>3</cost> 
</book> 
</data>

XML  不会

解决问题:

方法1.xfdipzone答:

<%
        cost=Request("cost")

        xmlfile=server.mappath("1.xml")
        set objxml=server.createobject("Msxml2.DOMDocument")
        objxml.async=false
        objxml.load(xmlfile)

        set currnodes=objxml.selectsinglenode("/data/book[cost='" & cost & "']")
        Response.write currnodes.childnodes(1).text
        set currnodes=nothing
        set objxml=nothing
%>

方法2.随风缘答:

也可以如此,加了判断获取的cost是否在xml中存在

<%
Dim bookId, bookName, i
bookId = 1
bookName = "没有书"
If Not IsNull(Request("bookId")) Then bookId = Int(Request("bookId"))

Dim strSourceFile, objXML, objRootList
strSourceFile = Server.MapPath("config.xml")
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.load(strSourceFile)
Set objRootList = objXML.documentElement
For i = 0 To objRootList.childNodes.Length -1
        If bookId = Int(objRootList.childNodes.Item(i).childNodes.Item(0).text) Then
                bookName = objRootList.childNodes.Item(i).childNodes.Item(1).text
                Exit For
        End If
Next
Set objXML = Nothing
Response.Write(bookName)
%>

 

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com