Groups | Blog | Home
all groups > dotnet xml > august 2003 >

dotnet xml : Same query against multiple docs



SQL Server Development Team [MSFT]
8/13/2003 11:28:21 AM
Compile the expression using the Compile method on the XPathNavigator and
cache the returned XPathExpression object. You can then use this object for
querying over differnt documents and you dont have to compile it every time.

XPathDocument doc1 = new XPathDocument("doc1.xml");

XPathNavigator nav1 = doc1.CreateNavigator();

XPathExpression expr = nav1.Compile("/");

XPathDocument doc2 = new XPathDocument("dump.xml");

XPathNavigator nav2 = doc2.CreateNavigator();

return nav2.Matches(expr);


-- Asad
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/copyright.htm.

[quoted text, click to view]

mono
8/13/2003 5:08:04 PM
Hello,

I have a collection of XML strings and want to find those that match a given
XPath expression.

I see lots of stuff to support evaluating the same expression against
different nodes in a single document but as far as I can see, if I want to
evaluate the expression against different docs, I have to recreate it
everytime.

Is that correct?

michael



mono
8/14/2003 12:50:01 PM
Asad,

Thanks, that answers the question.

I thought the XPathExpression would work only for the XPathNavigator that
created it.

Why isn't there a way of creating the expression without involving a
specific document, as can be done with Regex (which I see as analoguous)?

michael

[quoted text, click to view]

AddThis Social Bookmark Button