Finding Specific Nodes and Elements

In addition to being able to walk the entire XML document as shown in the previous section, you can also automatically select nodes using expressions defined in XPath (XML Path Language). The XPath standard can be found at http://www.w3.org/TR/xpath.

Basically, XPath allows you to define an expression that can be used to retrieve one or many nodes from the XML document, which you can then process. This allows you to write code that deals only with the nodes you care about. You don't have to write lots of code just to find the nodes your application uses.

The XmlNode class defines two methods that you can use to evaluate an expression and retrieve the resulting nodes. These methods are SelectNodes and SelectSingleNode ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.