How to Count XML Nodes from VB.NET

Count XML Child Nodes
This is how do you quickly count the child nodes of an XML file. Say that you have an XML data as follows:
< ?xml version="1.0" encoding="UTF-8"?>< title>Sql Server 2008 Query Performance ...< /title> 978-1-4302-1902-6 < title>Pro ASP.NET MVC Framework< /title> 978-1-4302-1007-8
To count the book items you may use counter iterating the books/book tags but this is how do you get the total number of book nodes in only one line.
Dim document As New XmlDocument
document.Load(xmlfilepath)
Dim count As Integer = document.SelectNodes("inventory/books/book").Count
Enjoy!
RSS 2.0 Comments Feed | Leave a Response | Trackback
Leave a Reply