Mega Code Archive

 
Categories / VB.Net / XML
 

XmlReader AttributeCount gets the number of attributes on the current node

Imports System Imports System.IO Imports System.Xml Public Class Sample     Public Shared Sub Main()         Dim xmlString As String = "<?xml version='1.0'?>" & _                         "<!-- This is a sample XML document -->" & _                         "<Items>" & _                           "<Item>test with a child element <more/> stuff</Item>" & _                         "</Items>"         ' Create an XmlReader         Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))             ' Display all attributes.             If reader.HasAttributes Then                 Console.WriteLine("Attributes of <" + reader.Name + ">")                 Dim i As Integer                 For i = 0 To (reader.AttributeCount - 1)                     Console.WriteLine("  {0}", reader(i))                 Next i                 ' Move the reader back to the element node.                 reader.MoveToElement()             End If         End Using     End Sub End Class