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?
[Test]
public void ReuseCompiledExpr()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml( "<Top> <A> <A1/> <A2/> </A > <B/> </Top>" );
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile( "*" );
nav.MoveToFirstChild(); // /Top
XPathNodeIterator iter1 = nav.Select( expr );
iter1.MoveNext(); // /Top/A
XPathNodeIterator iter2 = iter1.Current.Select( 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