XPathNavigator.Select() doesn't evaluate the expression, just parses it.
XPathNodeIterator.MoveNext() does actual "lasy" evaluation and positiones
iterator to next node.
XPathNodeIterator.Count() called firs time clones entire expression and
evaluate it counting nodes. I expect that Clone() is expensive on big
node-sets.
I'd like to see the repro: XML file, XPath expression, how you create
XPathNodeIterator and how you use it. (sdub.xslt@mailnull.com)
As work around you can try XPath function count(). It may be more efficient
then XPathNodeIterator.Count();
public virtual int Count {
get {
if (count == -1) {
XPathNodeIterator clone = this.Clone();
while(clone.MoveNext()) ;
count = clone.CurrentPosition;
}
return count;
}
}
Sergey
"Volkan" <volkan.paksoy@gmail.comwrote in message
news:1155060958.927174.172810@n13g2000cwa.googlegr oups.com...
Quote:
Hi,
>
I'm trying to compare two XML documents and i'm using XPath queries to
select nodes. XPathNavigator's Select method runs fast enough and
returns an XPathNodeIterator object. When i try to access this
iterator's Count property the process extremely slows down. If i just
iterate throgh 18.000 nodes and call XPathNavigator.Select to find
equivalent node from the other document it doesn't even take 1 second.
But in the same loop, when i try to access XPathNodeIterator.Count, (by
accessing i mean just assigning its value to a variable) it takes about
5 minutes.
>
I tried to use XPathNavigator.Evaluate and used XPath function boolean
inside the expression. And this reduced the elapsed time down to 3
minutes but it's still too much for me. (Btw, using XPath's count
function took longer.)
>
Can someone please give me some advise about how to overcome this
problem? Any input is appreciated.
>
Thanks in advance.
>
Best regards,
>
Volkan
>
|