2012-11-22 53 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