0

XML から個別の属性値を取得しようとしています: dim 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>

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 に答える