473,382 Members | 1,289 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,382 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 3769
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.