2015-11-27 74 views
0

父節點的屬性比方說,我是通過下面的XML迭代:VB.NET獲取XML

<Account Info="1234"> 
    <Number>3333</Number> 
</Account> 
<Account Info="0007"> 
    <Number>4444</Number> 
</Account> 

Dim MyNodes As XmlNodeList = xmldoc.GetElementsByTagName("Account") 

For Each node As XmlNode In MyNodes 
    'Get attribute of the current 'Info' node 
Next 

我需要以某種方式去內環路回來拿到父節點的屬性值。

幫助感謝!

回答

0

XmlNodeParentNode財產

Dim nodes As XmlNodeList = xmldoc.GetElementsByTagName("Account") 
For Each node As XmlNode In nodes 
    Dim parentNode As XmlNode = node.ParentNode 
    If parentNode Is Nothing OrElse parentNode.Attributes Is Nothing Then 
     Continue For 
    End If 
    Dim attribute As XmlAttribute = parentNode.Attributes.ItemOf("SomeAttribute") 
    If attribute Is Nothing Then 
     Continue For 
    End If 
    Console.WriteLine(attribute.Value) 
Next 
+0

甜,將給這個去 – levis84

+0

OK,貌似我沒必要去父級別。 只需要這一行: 昏暗的屬性作爲XmlAttribute = parentNode.Attributes.ItemOf(「SomeAttribute」) 將標記爲正確的答案,如果你可以好心編輯。謝謝 – levis84