473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

XPathNodeIterator.Count Performance Issues

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

Aug 8 '06 #1
2 3766
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. (sd*******@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" <vo***********@gmail.comwrote in message
news:11**********************@n13g2000cwa.googlegr oups.com...
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

Aug 8 '06 #2

Hi Sergey,

Thanks you for your reply.

Below is how i do what i aim to do :

// Load files to XPathDocuments
XPathDocument pathDocOld = new XPathDocument(strOldFilePath);
XPathDocument pathDocNew = new XPathDocument(strNewFilePath);

// Create XPathNavigators
navOld = pathDocOld.CreateNavigator();
navNew = pathDocNew.CreateNavigator();

// Select main nodes from both documents
XPathNodeIterator iteratorOld =
navOld.Select("/Message/RestrictionList/*");
XPathNodeIterator iteratorNew =
navNew.Select("/Message/RestrictionList/*");

// Start looping with new document.
while (iteratorNew.MoveNext())
{
// For each item find the corresponding one in the old document
iteratorOldSub =
navOld.Select/Message/RestrictionList/RestrictedItem[@ItemId=\"" +
strItemID + "\"]");

if( iteratorOldSub.Count == 0 ) (1)
{
// Couldn't find the item in the old document so mark this one as
Inserted in the output.
}

}

As i mentioned earlier, it takes 1 sec with code block (1) and 5 mins
with it.

Then i tried :
bool bExists =
(bool)navOld.Evaluate("boolean(/Message/RestrictionList/RestrictedItem[@ItemId=\""
+ strItemID + "\"] )");

if( bExists )
{

}

This works twice faster but still not enough for me. I wonder what am i
doing wrong.

So any suggestions to improve the performance?

Thanks.

Volkan

Aug 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rolando Barberis | last post by:
I am trying to determine the number of columns that are returned from a stored procedure using TSQL. I have a situation where users will be creating their own procedures of which I need to call and...
1
by: csomberg | last post by:
SQL 2000 I have inherited an application where many of the automated processes call a proc that simply returns the number of records with a NEW status. In watching the process in SQL, I see...
1
by: panik | last post by:
Hi, say I have an xml file with an X number of nodes I want to loop through (to, for example, display each node as a HyperLink in an asp.net webpage). Which of both is best practice: 1. Loop...
2
by: avnrao via .NET 247 | last post by:
Hi, please clarify this doubt about XPathNodeIterator..the following XSLT uses this.. my doubt is, by looking at the XSLT, i thought the output to be Book1..but the actual output is...
4
by: Jamie da Silva | last post by:
I couldn't find a better resource for reporting a possible .NET Framework 1.1 (SP0 & 1) bug, so if this is not the proper forum, please let me know. The problem appears to occur when using...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
3
by: KJ | last post by:
It is true that there is no way to get the outerXml of XPathNodeIterator.Current? Please say it isn't so.
2
by: R. Todd | last post by:
I noticed today that when I have an ASP.NET web page with AspCompat="true", the CCW count tracked by the peformance monitor increases every time the page is loaded. Clicking refresh causes the...
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.