XPathExpressions and XPathNavigators 
Author Message
 XPathExpressions and XPathNavigators

I have a set of XPath expressions which will be evaluated against a series
of XML documents.  I'd prefer to compile each XPath expression only once,
rather than once per document.  (For performance reasons, this is a
requirement.)  My first cut at this uses code like (slightly edited for
clarity, please forgive any typos):

        String xpath; // XPath expression
        String xmlFile; // XML file name

         XmlDocument xd = new XmlDocument();
         xd.Load(new FileStream(xmlFile, FileMode.Open));
         XPathNavigator nav = xd.CreateNavigator();
        XPathExpression expr = nav.Compile(xpath);
        Object o = nav.Evaluate(expr);

I'm a bit confused that XPathExpressions are created by a method on
XPathNavigator .  What is the relationship between an XPathExpression and
the XPathNavigator  which created it?  In particular, I'd like to know
whether there is any restriction on the XPathNavigator's the expression can
later be evaluated on.  That is, can I do something like:

        // Evlaute existing expression on array of XML files
        String xmlFiles[];    // names of XML documents
        for (int i = 0; i < xmlFile.Length; i++)
        {
             XmlDocument xd2 = new XmlDocument();
             xd2.Load(new FileStream(xmlFiles[i], FileMode.Open));
             XPathNavigator nav2 = xd2.CreateNavigator();

            // Evaluate existing expression on newly parsed document
             Object o2 = nav2.Evaluate(expr);
        }



Sat, 20 Nov 2004 00:50:43 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Modify result of XPathNavigator return value

2. XPathNavigator with namespaces and default values?

 

 
Powered by phpBB® Forum Software