XmlElement over XPathNavigator

Topics: Developer Forum
Sep 11, 2009 at 8:19 AM

Hi, I made a simple implementation of XPathNavigatorXmlElement inheriting from XmlElement, which "simulates" XmlElement over XPathNavigator. It allows to get XmlNodeList even for XPathNavigator instances not implementing IHasXmlNode (only for XPathNodeType.Element).

Now I can do things like this:
XPathDocument doc = new XPathDocument(new StringReader(xmlData));
XmlNodeList records = XPathCache.SelectNodes(doc, xpath);
foreach (XmlElement record in records)
{ ...}

It could be included MVP.XML if found useful enough...

Sep 12, 2009 at 8:26 PM

XmlElement being your own custom type?

Sep 14, 2009 at 7:44 AM

class XPathNavigatorXmlElement: XmlElement

When filling the NodeList, I have a code like this:

private XmlNode getNode(XPathNavigator navigator)
  IHasXmlNode hasNode = navigator as IHasXmlNode;
  if (hasNode != null)
    return hasNode.GetNode();

  if (navigator.NodeType == XPathNodeType.Element)
    return new XPathNavigatorXmlElement(navigator);

  throw new Exception("...")

Sep 14, 2009 at 3:48 PM

That's cool!


Looks like a valuable addition to the project :)

Sep 14, 2009 at 5:01 PM

ok, I'll add some comments inside the source code. Where can I send or upload it? I'v never been commiting any code to CodePlex...