I'm using a webservice which returns an XmlElement object to my c# program. I would like to read information from the XmlElement using Xpath. What is the best way to create an XPathDocument from the XmlElement?
+2
A:
You can create a navigator directly against the XmlElement and use your xpath from there with the navigators Select* methods, no XPathDocument required.
annakata
2009-02-24 09:48:17
Thanks for your answer :)
macleojw
2009-02-24 10:09:12
+3
A:
If you have an XmlElement
, can you not just use SelectNodes()
/ SelectSingleNode()
?
Also, all XmlNode
s are IXPathNavigable
, allowing you to get a navigator.
Finally, you can use new XmlNodeReader(element)
, and use this to create an XPathDocument
using the overload that accepts an XmlReader
.
Marc Gravell
2009-02-24 09:49:40