Mega Code Archive

 
Categories / VB.Net / XML
 

XmlTextReader 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 xmlData As String         xmlData = "<book>" & _                   "  <title>C#</title>" & _                   "  <price>5.95</price>" & _                   "</book>"         Dim reader As XmlTextReader = New XmlTextReader(New StringReader(xmlData))         If reader.HasAttributes Then             Console.WriteLine("Attributes of <" & reader.Name & ">")             Dim i As Integer             For i = 0 To reader.AttributeCount - 1                 reader.MoveToAttribute(i)                 Console.Write(" {0}={1}", reader.Name, reader.Value)             Next i             reader.MoveToElement() 'Moves the reader back to the element node.         End If     End Sub End Class