473,804 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusing XPathExpression in multiple iterations

Is there some reason why I shouldn't be able to use the same XPathExpression
simultaneously in multiple iterations? The test below illustrates the
problem. It seems that creating two XPathNodeIterat ors with the same
expression creates a coupling between the iterators so they always point to
the same position. Anyone care to comment?

[Test]
public void ReuseCompiledEx pr()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml( "<Top> <A> <A1/> <A2/> </A > <B/> </Top>" );

XPathNavigator nav = doc.CreateNavig ator();
XPathExpression expr = nav.Compile( "*" );

nav.MoveToFirst Child(); // /Top
XPathNodeIterat or iter1 = nav.Select( expr );
iter1.MoveNext( ); // /Top/A
XPathNodeIterat or iter2 = iter1.Current.S elect( expr ); // Replace expr
with "*" and it works!
iter2.MoveNext( ); // /Top/A/A1
iter2.MoveNext( ); // /Top/A/A2
Assert.IsTrue( iter1.MoveNext( ) ); // /Top/B <--- Returns false!
}

---
Steve
Nov 12 '05 #1
2 2770
You have to call Clone explicitly: XPathNodeIterat or iter2 =
iter1.Current.S elect( expr.Clone() ); // Replace expr
Because there are no guaranties about concurrent usage of XPathExpression is
not really a bug, but a usability issue. We will consider fixing it in the
next version.
"Steve Taylor" <NO**********@S PAMhotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Is there some reason why I shouldn't be able to use the same
XPathExpression
simultaneously in multiple iterations? The test below illustrates the
problem. It seems that creating two XPathNodeIterat ors with the same
expression creates a coupling between the iterators so they always point
to
the same position. Anyone care to comment?

[Test]
public void ReuseCompiledEx pr()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml( "<Top> <A> <A1/> <A2/> </A > <B/> </Top>" );

XPathNavigator nav = doc.CreateNavig ator();
XPathExpression expr = nav.Compile( "*" );

nav.MoveToFirst Child(); // /Top
XPathNodeIterat or iter1 = nav.Select( expr );
iter1.MoveNext( ); // /Top/A
XPathNodeIterat or iter2 = iter1.Current.S elect( expr ); // Replace expr
with "*" and it works!
iter2.MoveNext( ); // /Top/A/A1
iter2.MoveNext( ); // /Top/A/A2
Assert.IsTrue( iter1.MoveNext( ) ); // /Top/B <--- Returns false!
}

---
Steve

Nov 12 '05 #2
You have to call Clone explicitly: XPathNodeIterat or iter2 =
iter1.Current.S elect( expr.Clone() ); // Replace expr
Because there are no guaranties about concurrent usage of XPathExpression is
not really a bug, but a usability issue. We will consider fixing it in the
next version.
"Steve Taylor" <NO**********@S PAMhotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Is there some reason why I shouldn't be able to use the same
XPathExpression
simultaneously in multiple iterations? The test below illustrates the
problem. It seems that creating two XPathNodeIterat ors with the same
expression creates a coupling between the iterators so they always point
to
the same position. Anyone care to comment?

[Test]
public void ReuseCompiledEx pr()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml( "<Top> <A> <A1/> <A2/> </A > <B/> </Top>" );

XPathNavigator nav = doc.CreateNavig ator();
XPathExpression expr = nav.Compile( "*" );

nav.MoveToFirst Child(); // /Top
XPathNodeIterat or iter1 = nav.Select( expr );
iter1.MoveNext( ); // /Top/A
XPathNodeIterat or iter2 = iter1.Current.S elect( expr ); // Replace expr
with "*" and it works!
iter2.MoveNext( ); // /Top/A/A1
iter2.MoveNext( ); // /Top/A/A2
Assert.IsTrue( iter1.MoveNext( ) ); // /Top/B <--- Returns false!
}

---
Steve

Nov 12 '05 #3

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

Similar topics

1
3739
by: Vikas Vijay | last post by:
hello all, I have a c++ code in which is sth like while(i < N) { .... do some processing in c++ to create file abc system("simulator_name < abc") ......c++ ... processing...... }
0
358
by: Steve Taylor | last post by:
Is there some reason why I shouldn't be able to use the same XPathExpression simultaneously in multiple iterations? The test below illustrates the problem. It seems that creating two XPathNodeIterators with the same expression creates a coupling between the iterators so they always point to the same position. Anyone care to comment? public void ReuseCompiledExpr() { XmlDocument doc = new XmlDocument();
4
1160
by: gajba | last post by:
Hi, from an XML beginner.. I have an XML like the one below: <root> <vendor name="Microsoft"> <!-- additional sub-tags and items --> </vendor> <vendor name="Sun"> <!-- additional sub-tags and items -->
4
4511
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
0
1400
by: Philipp Schumann | last post by:
Hi there, don't know whether anyone ran into this issue formerly (in .NET 1.0). I have an XML document with a default namespace (indicating the target namespace of the XML Schema used to validate the document): <ObjectIndex xmlns="http://ref.devlink.net/opal/runtime/ObjectBaseSchema
0
1056
by: LockyBoy | last post by:
Hi Have created an xml document with an xmltextwriter with a namespace, so it can be validated against an xsd schema. Later in my application, I want to extract values from the xml and am using xpathexpression. Because I have a namespace in the xml, I have to use the xmlNameSpaceManager and comile an xpathquery as below:
12
467
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. I find that the second one always is blank. I assume this is because the DataReader is read-forward only. ******************************************************** connect.open() cmdSelect = New OleDbCommand("exec populateCities 'North...
16
5729
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and got a nudge in the right direction from Mr. Kreft. I promised to provide details once working, so here it is. The code is shown below. My next step is to build this technique into my application. I'm hoping for substantial performance gain. ...
2
2325
by: darrel | last post by:
I have an XML file that looks like this: <Counties> <County> <District>2</District> <CountyName>Palm</CountyName> </County> <County> <District>3</District> <CountyName>McCarthy</CountyName>
0
9594
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
10595
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...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6862
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
5530
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...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.