simon
simon

Reputation: 185

Using xpath on a stream

is it possible to use xpath on a streamed xml file using streamreader (file obtained from the internet) ?

I know the exact location of the data i need but not sure how best to get at it?

Thanks

Upvotes: 4

Views: 1919

Answers (2)

Robert Rossney
Robert Rossney

Reputation: 96722

While it would be theoretically possible to build a stream reader that executed an XPath query on a stream, I don't know of any such implementation; the XPath processors in the .NET framework (in XDocument, XmlDocument, and XPathDocument) all read the document into memory before executing the query. All of these objects can read streams.

If speed is a concern, XPathDocument and XPathNavigator are likely to be the fastest, since those objects let you directly iterate over the nodes as the query executes, rather than executing the query and returning a list of nodes for you to iterate over. (Actually XDocument.XPathEvaluate may do this too; the documentation doesn't say.)

Upvotes: 1

Anders Abel
Anders Abel

Reputation: 69260

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

Upvotes: 1

Related Questions