获取XML节点不同的属性 [英] Get distinct attributes for XML nodes

查看:114
本文介绍了获取XML节点不同的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I`ve一直试图让从不同的属性值
XML:
暗淡我,xmlOx,编曲(100)
xmlOx具有以下XML结构

I`ve been trying to get distinct attribute values from the 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

一样,在​​这里我已经获得的x属性值,但我不 T需要duplicates.Then我需要的值添加到VBScript中的数组。

Like,here ive to get "x" attribute values but I dont need duplicates.Then I need to add the values to an array in vbscript.

请有人告诉我,我们怎么办呢?

Please someone tell me how we do it?

推荐答案

该理论这里

code:

  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

这篇关于获取XML节点不同的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆