让我们说我正在迭代以下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 :(得分:0)
XmlNode
有一个ParentNode
属性
示例强>
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