Možné to je pomocí system.xml(DOM) nebo system.xml.linq(Linq to XML) system.xml
Imports System.Xml
Module Module1
Sub Main()
Dim xmlDoc As New XmlDocument
xmlDoc.Load(My.Application.Info.DirectoryPath & "\XmlFile1.xml")
Dim nl As XmlNodeList = xmlDoc.SelectNodes("/otazky/otazka")
'Pokud Vás zajímá počet nodů otázka
Dim pocet As Integer = nl.Count
Console.WriteLine("Počet otázek = " & pocet.ToString)
'Pokud Vás zajímá nejvyšší Id otázky
pocet = 0
For Each n As XmlNode In nl
Dim atrId As Integer = Convert.ToInt32(n.Attributes("id").InnerText)
If atrId > pocet Then pocet = atrId
Next
Console.WriteLine("Nejvyšší Id = " & pocet.ToString)
Console.ReadKey()
End Sub
End Module
System.xml.linq
Imports System.Xml.Linq
Module Module1
Sub Main()
Dim xDoc As XDocument = _
XDocument.Load(My.Application.Info.DirectoryPath & "\XmlFile1.xml")
Dim query As IEnumerable(Of XElement) = From o In xDoc.<otazky>.<otazka> _
Order By o.@id Ascending _
Select o
'Počet otazka v otazky
Dim pocet As Integer = query.Count
Console.WriteLine("Počet otázek = " & pocet.ToString)
pocet = 0
'Nejvyšší Id
For Each xe As XElement In query
Dim atrId As Integer = Convert.ToInt32(xe.@id)
If atrId > pocet Then pocet = atrId
Next
Console.WriteLine("Nejvyšší Id = " & pocet.ToString)
Console.ReadKey()
End Sub
End Module
|