Asp classic 获取XML节点的不同属性
我一直在尝试从 XML: 尺寸i、xmlOx、arr(100) “xmlOx”具有以下xml结构Asp classic 获取XML节点的不同属性,asp-classic,vbscript,Asp Classic,Vbscript,我一直在尝试从 XML: 尺寸i、xmlOx、arr(100) “xmlOx”具有以下xml结构 <root> <a x="Animal" y="Bird"/> <a x="Animal" y="Bird"/> <a x="Country" y="Bird"/> <a x="Animal" y="Bird"/> </root> 比如,这里我ve获取“x”属性值,但我不需要重复的属
<root>
<a x="Animal" y="Bird"/>
<a x="Animal" y="Bird"/>
<a x="Country" y="Bird"/>
<a x="Animal" y="Bird"/>
</root>
比如,这里我ve获取“x”属性值,但我不需要重复的属性值。然后我需要将这些值添加到vbscript中的数组中
请有人告诉我我们是怎么做的吗?理论是这样的
代码:
Dim-sXml:sXml=Join(数组(_
"" _
, "" _
, "" _
, "" _
, "" _
, "" _
))
Dim-oXDoc:Set-oXDoc=CreateObject(“Msxml2.DOMDocument”)
oXDoc.loadXml sXml
WScript.Echo oXDoc.xml
Dim xObjXml:Set xObjXml=oXDoc.documentElement.childNodes
Dim dicAttrs:Set dicAttrs=CreateObject(“Scripting.Dictionary”)
昏暗的我
对于i=0到xObjXml.length-1
Dim a:a=xObjXml(i).getAttribute(“x”)
指示TRS(a)=指示TRS(a)+1
下一个
尺寸aAttrs:aAttrs=dicttrs.Keys()
Echo连接(aAttrs)
输出:
<root>
<a x="Animal" y="Bird"/>
<a x="Animal" y="Bird"/>
<a x="Country" y="Bird"/>
<a x="Animal" y="Bird"/>
</root>
Animal Country
动物王国
谢谢你的回答。请查看我的帖子更新并回复。请使用确切的变量。@user1495475-很抱歉,我不能这样做,因为你的代码片段没有意义。我不能放所有的代码,所以我
放了一些随机的xml,请看看你是否能帮上忙。主要问题是它在“dicAttrs.Keys()”上抛出了错误“需要Microsoft VBScript运行时(0x800A01A8)对象”。
Dim sXml : sXml = Join(Array( _
"<root>" _
, "<a x=""Animal"" y=""Bird""/>" _
, "<a x=""Animal"" y=""Bird""/>" _
, "<a x=""Country"" y=""Bird""/>" _
, "<a x=""Animal"" y=""Bird""/>" _
, "</root>" _
))
Dim oXDoc : Set oXDoc = CreateObject("Msxml2.DOMDocument")
oXDoc.loadXml sXml
WScript.Echo oXDoc.xml
Dim xObjXml : Set xObjXml = oXDoc.documentElement.childNodes
Dim dicAttrs : Set dicAttrs = CreateObject("Scripting.Dictionary")
Dim i
For i = 0 To xObjXml.length - 1
Dim a : a = xObjXml(i).getAttribute("x")
dicAttrs(a) = dicAttrs(a) + 1
Next
Dim aAttrs : aAttrs = dicAttrs.Keys()
WScript.Echo Join(aAttrs)
<root>
<a x="Animal" y="Bird"/>
<a x="Animal" y="Bird"/>
<a x="Country" y="Bird"/>
<a x="Animal" y="Bird"/>
</root>
Animal Country