473,836 Members | 1,861 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 2773
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
3740
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
1057
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
5732
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
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10819
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
10567
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
10237
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
9349
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...
0
5641
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...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4437
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
3
3100
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.