Method
Advances the reader to the next attribute of the current node.
Syntax
Public Overloads Function MoveToNextAttribute () As Boolean
Parameters: None
Return Value
True if the reader is advanced to the next attribute; False if there are no more attributes.
Remarks
This method moves the reader to the next attribute of the current node. If the current node has no attributes, or if all attributes have already been visited, this method returns False.
The reader starts at the beginning of the attribute list when it is positioned on an element node. Each call to MoveToNextAttribute moves to the subsequent attribute.
To get the value of the current attribute, use the Value property.
To get the name of the current attribute, use the Name property.
To get the local name of the current attribute, use the LocalName property.
To get the namespace URI of the current attribute, use the NamespaceURI property.
To return to the element node, use the MoveToElement method.
Requirements
Namespace: System.Xml
Assembly: System.Xml.dll (in .NET Framework or .NET Core)
Example
The following example reads the attributes of an XML element.
Imports System
Imports System.Xml
Public Class Example
Public Shared Sub Main()
Dim xmlString As String = "<root xmlns:a='urn:schemas-microsoft-com:axmlfn' attr1='value1' attr2='value2'>Content</root>"
Dim reader As New XmlNodeReader(New System.Xml.XmlTextReader(New System.IO.StringReader(xmlString)))
Try
reader.Read() ' Move to the root element
If reader.IsStartElement() Then
' Move to the first attribute
While reader.MoveToNextAttribute()
Console.WriteLine("Attribute: {0} = {1}", reader.Name, reader.Value)
End While
reader.MoveToElement() ' Move back to the element node
Console.WriteLine("Element: {0}", reader.Name)
End If
Finally
reader.Close()
End Try
End Sub
End Class