0

我一直在尝试从 XML 中获取不同的属性值:dim i,xmlOx,arr(100) "xmlOx" has following xml structure

  <root>
    <a x="Animal" y="Bird"/>
    <a x="Animal" y="Bird"/>
    <a x="Country" y="Bird"/>
    <a x="Animal" y="Bird"/>
    </root>

ASP:

for i=0  xmlOx.selectNodes("a").length-1
 arr(i)=xmlOx(i).selectNodes("a").getAttribute("x")
next

就像,这里ve to get "x" attribute values but I don需要重复。然后我需要将值添加到 vbscript 中的数组中。

请有人告诉我我们是怎么做的?

4

1 回答 1

0

理论就在这里

代码:

  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
于 2012-11-22T14:45:06.760 回答