xml求助

ldw701 2004-07-05 09:36:08
如何解析一下XML文件中的内容,请各位XDJM帮我一下,我不熟悉XML!谢谢了!

<?xml version="1.0" encoding="UTF-8" ?>
- <password>
<Status>-1</Status>
<ErrorReason>parameter not correct</ErrorReason>
</password>
我要获取 satuts和 errorreason中的值!在ASP中该如何写代码?
...全文
166 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2004-08-13
  • 打赏
  • 举报
回复
大家PP,近来做的笨狼xml解析工具


<html>
<head>
<style>
table
{
border-collapse: collapse;
border-width: 4;
border-style: double;
border-color:#15336F;
font-size:12px;
}
body
{
font-size:12px;
}
</style>
<body>
<INPUT type="file" id=file1 name=file1>请输入xml文件路径
<INPUT type="button" value="确定" onclick = "vbs:analyse ">
<table border="1" id=xmlInfo>
<tr id=myTR1>
<td> 节点名称 </td><td> 属性名称 </td>
</tr>
</table>
</body>
<title>笨狼xml解析工具</title>
</head>
<script language="vbScript" >
'**************************************
'****作者: 超级大笨狼 superdullwolf****
'**************************************

public dic
set dic = CreateObject("Scripting.Dictionary")

sub analyse()

dim doc
set doc = CreateObject("Microsoft.XMLDOM")
doc.async=False
dic.RemoveAll
if not doc.load(file1.value) then
alert "文件加载失败,请检查文件是否存在!"
else
Set rootNode = doc.DocumentElement
getnode rootNode
'清空行
removeRows xmlInfo
addRow xmlInfo
end if


end sub

sub addRow(TB)
'添加行
dim myTR,myTD,kkk
for each kkk in dic.Keys
set myTR = TB.insertRow
set myTD = myTR.insertCell
myTD.innerText = kkk
set myTD = myTR.insertCell

if len(trim(dic.Item(kkk))) > 0 then
myTD.innerText = dic.Item(kkk)
else
myTD.innerText = ""
end if
next
end sub

sub removeRows(TB)
dim TR
for each TR in TB.rows
if TR.rowIndex>0 then TR.removeNode(true)
next
end sub

sub getnode(myNode)
on error resume next
for each childNode in myNode.childNodes
if childNode.nodeName<>"#text" then
if not(dic.Exists(childNode.nodeName)) then
if childNode.Attributes.length>0 then
dic.Add childNode.nodeName, makeString(childNode.Attributes )
else
dic.Add childNode.nodeName,""
end if
else
dic.Item(childNode.nodeName) = exclude(dic.Item(childNode.nodeName),childNode.Attributes )
end if
end if
if childNode.childNodes.length > 0 then getnode childNode
next
end sub

function exclude(myString,collection)
dim sss,ccc,kkk,d
set d = CreateObject("Scripting.Dictionary")

for each sss in split(myString,",")
if not d.Exists(sss) then d.Add sss,sss
next

for each ccc in collection
if not d.Exists(ccc.name) then d.Add ccc.name,ccc.name
next

for each kkk in d.Keys
exclude = exclude & kkk & " "
next

exclude = replace(trim(exclude)," ",",")
end function

function makeString(collection)
dim ccc
makeString = " "

for each ccc in collection
makeString = makeString & ccc.name & " "
next
makeString = replace(trim(makeString)," ",",")
end function

</script>
</html>
aspczlover 2004-07-08
  • 打赏
  • 举报
回复
解决了吗?
aspczlover 2004-07-05
  • 打赏
  • 举报
回复
<script language="vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml") '你的xml文件名 要保证路径正确
'载入note.xml文档

for each x in xmlDoc.documentElement.childNodes
'遍历xmlDoc对象的根节点的子节点
document.write(x.nodeName)
'输出节点名称
document.write(":")
document.write(x.text)
'输出节点文本
document.write("<br>")
next
set xmldoc=nothing
</script>
guihengzhang 2004-07-05
  • 打赏
  • 举报
回复
用dom 来操作
给你一个经典的例子
http://www.fixdown.com/article/article/1023.htm
xdk 2004-07-05
  • 打赏
  • 举报
回复
一楼。。。

28,391

社区成员

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

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