The way to do this is to use an XPathDocument that can accept a stream, so you can use a StringReader.
This returns the value in direct read mode without the overhead of loading the entire XML DOM into memory using an XmlDocument.
Here is an example that returns the value of the first node that satisfies the XPath request:
public string extract(string input_xml)
{
XPathDocument document = new XPathDocument(new StringReader(input_xml));
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator node_iterator = navigator.Select(SEARCH_EXPRESSION);
node_iterator.MoveNext();
return node_iterator.Current.Value;
}
source
share