asp按特定值搜索xml某节点

bxbacn 2010-11-19 11:28:08
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item>
<i name="english" value="英文" />
<i name="chinese" value="中文" />
</item>
</root>


需要搜索 /root/item 下的i 中name值为 english的节点的 value值,并读出值为英文
如果条件是chinese 那么值又为中文

请问要怎么操作
...全文
52 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bxbacn 2010-11-20
  • 打赏
  • 举报
回复
谢了,原来是我的xml文档出错了,我说我怎么一直查找不成功,好还有你的回复
hookee 2010-11-20
  • 打赏
  • 举报
回复

<%
Response.Write search("english")
Response.Write search("chinese")

Function search(sValue)

s = "<?xml version=""1.0"" encoding=""utf-8"" ?>" &_
"<root>" &_
"<item>" &_
" <i name=""english"" value=""英文"" />" &_
" <i name=""chinese"" value=""中文"" />" &_
"</item>" &_
"</root>"

Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
.async = False
.validateOnParse = False
.preserveWhiteSpace = False
.resolveExternals = False
.loadXML s
If .parseError.errorCode <> 0 Then
sErrMsg = .parseError.errorCode & "|" &_
.parseError.srcText & "|" & .parseError.reason
Set oDoc = Nothing
search = sErrMsg
Exir
End If
Set oNode = .selectSingleNode("/root/item/i[@name='" & Replace(sValue, "'", "'") & "']")
If oNode Is Nothing Then
search = ""
Else
search = oNode.getAttribute("value")
End If
End With
Set oDoc = Nothing
End Function
%>
bxbacn 2010-11-20
  • 打赏
  • 举报
回复
有没有人回答一下这个问题啊

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧