473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPathNodeIterat or.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 XPathNodeIterat or 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 XPathNodeIterat or.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 3825
XPathNavigator. Select() doesn't evaluate the expression, just parses it.

XPathNodeIterat or.MoveNext() does actual "lasy" evaluation and positiones
iterator to next node.
XPathNodeIterat or.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
XPathNodeIterat or and how you use it. (sd*******@mail null.com)

As work around you can try XPath function count(). It may be more efficient
then XPathNodeIterat or.Count();

public virtual int Count {
get {

if (count == -1) {

XPathNodeIterat or clone = this.Clone();

while(clone.Mov eNext()) ;

count = clone.CurrentPo sition;

}

return count;

}

}

Sergey

"Volkan" <vo***********@ gmail.comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.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 XPathNodeIterat or 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 XPathNodeIterat or.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(s trOldFilePath);
XPathDocument pathDocNew = new XPathDocument(s trNewFilePath);

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

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

// Start looping with new document.
while (iteratorNew.Mo veNext())
{
// 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.Ev aluate("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
795
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 place those results in a temp table. I will not be able to modify those users procedures. I figure if I have the number of columns I can dynamically create a temp table with the same number of columns, at which point I can then perform an INSERT...
1
1592
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 this ends up blocking a lot of processes - many like this are called every 5-30 seconds ... I wish to replace COUNT(*) with EXISTS if that will make things operate
1
8419
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 through a NodeList (e.g.: foreach XmlNode in XmlNodeList ... ) 2. or use an XPathNodeIterator Are there any differences in performance? Are both used for different
2
3596
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 Book1Book2Book3Book4.. as I understand, func method is called only once and XPathNodeIterator.MoveNext() is called only once..and how is this concatenated output?? tia, avnrao.
4
1737
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 "self::" to match the current node of an XPathNavigator. In this case the resulting XPathNodeIterator returns a Count of 1 even though it is properly empty as evidenced by MoveNext() returning false. In the following sample code (compiled as a...
4
5435
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
3
5328
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
1435
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 count to increment. The count grows into the hundreds before it drops, but it never drops back to 0. Can anyone explain what's going on? For what managed object is a CCW being created? What impact will this have on memory usage? I'm in the...
6
7707
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 using an XPathNodeIterator? Or should I be using something else? In the sample that follows: 1. Grab all "Page" nodes. 2. Loop through all the nodes.
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.