XPathNavigator vs. IXPathNavigable
A few weeks ago, some debate sparked regarding the IBlogThis (now IBlogExtension) interface, and, at that time, Don suggested using IXPathNavigable or XPathNavigator over XmlDocument through the interface. And so, we now have an IBlogExtension interface that uses IXPathNavigable indeed.
However, this raises a small question: Why would you prefer IXPathNavigable over XPathNavigator directly? After all, the former has only one method (CreateNavigator()) so you can pretty much only use it to get an XPathNavigator instance anyway.
While on the topic, I figure this could be a good time to make a few wishes regarding the Xml support in the .NET framework: Bridge the different abstractions you guys provide! Overall, I really like the XML support in the framework (especially compared to what we used to have before), but sometimes, you find significant gaps in how the different abstractions provided interact. So yes, I'd like things like an XPathNavigatorReader and to be provided by the framework. Is that too much to ask? I think not.






Tomas,
I’m probably most directly responsible for the design of the next incarnation of XPathNavigator and I’m well aware of the issues you point out and we plan to do something about them in the next version of the .NET Framework.
As for choosing XPathNavigator over IXPathNavigable, I’d prefer taking an XPathNavigator as a method parameter because an application may be handed a navigator not necessarily an instance of IXPathNavigable which it may want to pass to your method but would be SOL if you only accept IXPathNavigable. However taking a navigator means you burden your users with having to make CreateNavigator() calls. Most users prefer
xslTransform.Transform(doc, arglist, stream);
to
XPathNavigator nav = doc.CreateNavigator();
xslTransform.Transform(nav, arglist, stream);
Dare,
Thanks for the comments. I’m afraid I don’t quite get your last argument (wrong words?).
Am I right in understanding that you’d prefer to pass an XPathNavigator explicitly over just an IXPathNavigable?
Tomas,
People prefer to pass IXPathNavigable to explicitly calling CreateNavigator(). Of course, most of these people don’t realize they are passing IXPathNavigable, all they know that is that it just works.
However I personally prefer that methods accept XPathNavigator.
I hope that explains it better.