从xml元素获取所有属性

从xml元素获取所有属性,xml,vb.net,Xml,Vb.net,我有一个函数,可以返回各种元素属性。 在这种情况下,我需要获取给定元素的所有属性 我设法读取正确的元素,并使用以下代码: If XMLReader.HasAttributes Then For Each Attribute As XmlAttribute In XmlNodeType.Attribute retVal = Attribute.Name + "+" + Attribute.Value Next End If 哪个明显的错误是不对的,因为在我开始使用它之前,它会抛出一个错误

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

If XMLReader.HasAttributes Then
 For Each Attribute As XmlAttribute In XmlNodeType.Attribute
  retVal = Attribute.Name + "+" + Attribute.Value
 Next
End If
哪个明显的错误是不对的,因为在我开始使用它之前,它会抛出一个错误
表达式的类型为“System.Xml.XmlNodeType”,它不是集合类型

有人告诉我正确的方法吗

如果它有一个
属性
属性,它是一个集合

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

基本上你是对的。。。使用附加参数<在ElementControl.DocumentElement.ChildNodes(5)、ChildNodes(2)、ChildNodes(属性(1)-1)、Attributes retVal=Attribute.Name++“++”Attribute.Value NextAttibute(1)是来自代码的节点数,这是因为这里有500个子节点。其他子节点是之前的节点,直到我们找到感兴趣的节点。。。非常感谢你,你的回答非常好,并指出了我的错误,我已经。。。再次感谢你