从xml元素获取所有属性

时间:2014-02-20 17:44:48

标签: xml vb.net

我有一个函数可以返回各种Element属性 在这种情况下,我需要从给定的元素中获取所有属性 我设法阅读正确的元素,并使用以下代码:

If XMLReader.HasAttributes Then
 For Each Attribute As XmlAttribute In XmlNodeType.Attribute
  retVal = Attribute.Name + "+" + Attribute.Value
 Next
End If

哪个明显不合适,因为在我开始使用它之前它会引发错误 Expression is of type 'System.Xml.XmlNodeType', which is not a collection type
有没有人告诉我正确的方法呢?

1 个答案:

答案 0 :(得分:2)

XMLDocument Attributes属性是一个集合。

Dim xmldoc As New XmlDocument
xmldoc.Load("path to file")
Dim concatValue As String = ""
For Each atr As XmlAttribute In xmldoc.DocumentElement.Attributes
  concatValue &= atr.Name & "+" & atr.Value
Next
相关问题