New in .NET 2.0: XPathNavigator finally has SelectSingleNode() method

| 2 Comments | No TrackBacks

In .NET 2.0 XPathNavigator finally has SelectSingleNode() method! MSXML and XmlDocument (XmlNode actually) have it forever and it's so widely used because it's soooo handy. Obviously despite its name, XPathNavigator.SelectSingleNode() returns not a node, but node equivalent in XPathNavigator's data model - XPathNavigator. And this method is even better than XmlNode's one, because it has overloads accepting compiled XPathExpression, so when running within a loop you don't have to pay XPath compilation price on each iteration. That's another reason to switch completely to XPathNavigator API when processing XML in .NET 2.0.

Related Blog Posts

No TrackBacks

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/473

2 Comments

SelectSingleNode() isn't more efficient than Select(), it's just a matter of convenience for developer. And in .NET Select() never selects all nodes, so there is no difference between Select and SelectSingleNode with regard to perf- they are both fast.

It is nice feature, but I believe the MSXML library does nothing more than perform a XmlDocument.SelectNodes() and return the first resulting node.

It might give someone the idea however that SelectSingleNode() would be more eficient when only the first node is required, while it actually isn't... 8-)

Leave a comment