Using xpath in a stream

Is it possible to use xpath in an XML streaming file using streamreader (a file obtained from the Internet)?

I know the exact location of the data I need, but I don’t know how best to get this?

thanks

+4
source share
2 answers

Use the XDocument.Load(Stream, LoadOptions) to parse the XML from the stream. Then you can use XDocument.XPathEvaluate to get the value.

0
source

Although it is theoretically possible to build a stream reader that has executed an XPath request for a stream, I don't know of any such implementation; XPath processors in the .NET platform (in XDocument , XmlDocument and XPathDocument ) all read the document into memory before executing the request. All of these objects can read streams.

If speed is a problem, XPathDocument and XPathNavigator are likely to be the fastest, as these objects allow you to directly iterate over nodes as you execute the query, rather than run the query and return a list of nodes for you to iterate over. (Actually XDocument.XPathEvaluate can do this too, the documentation does not say.)

0
source

All Articles