2012-11-22 50 views
0

I`ve一直试图获得来自 XML不同的属性值不同的属性: 暗淡我,xmlOx,编曲(100) “xmlOx” 有以下的XML结构获取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吨需要duplicates.Then我需要添加值在VBScript中的数组。

请别人告诉我我们怎么做?

回答

0

理论是here

代码:

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 
+0

感谢answer.Please检查我的更新后,然后回信给please.Use确切的变量。 – user1495475

+0

@ user1495475 - 对不起,我不能那样做,因为你的代码片段没有意义。 –

+0

我不能放所有的代码,所以我把一些随机的XML,请看看你是否可以帮助它。 – user1495475