472,791 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

XPathNodeIterator.Count Bug?

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 console program), the results
from Test 2 & 10 are not correct.

static void Main(string[] args)
{
XPathDocument doc = new XPathDocument(new
StringReader("<root><a></a></root>"));
XPathNavigator nav = doc.CreateNavigator();

nav.MoveToFirstChild(); // now at "root"
Console.Out.WriteLine("Current Node Name: {0}\n",nav.Name);

RunSelectTest(nav,"self::root",1);
RunSelectTest(nav,"self::nomatch",2);

RunSelectTest(nav,"../root",3);
RunSelectTest(nav,"../nomatch",4);

RunSelectTest(nav,"a/self::a",5);
RunSelectTest(nav,"a/self::nomatch",6);

RunSelectTest(nav,"a",7);
RunSelectTest(nav,"nomatch",8);

nav.MoveToFirstChild(); // now at "a"

RunSelectTest(nav,"self::a",9);
RunSelectTest(nav,"self::nomatch",10);
}

static void RunSelectTest( XPathNavigator nav, string xpath, int testId )
{
Console.Out.WriteLine("--- Test {0} (\"{1}\") ---",testId,xpath);

XPathNodeIterator iter = nav.Select(xpath);
Console.Out.WriteLine("Select Iter Count: {0}",iter.Count);
Console.Out.WriteLine("Select Iter MoveNext: {0}",iter.MoveNext());
Console.Out.WriteLine(string.Empty);
}

Thanks,
Jamie da Silva
Silverlake Software LLC
Nov 12 '05 #1
4 1678
Jamie da Silva wrote:
XPathNodeIterator iter = nav.Select(xpath);
Console.Out.WriteLine("Select Iter Count: {0}",iter.Count);


I believe that's wrong. You must call MoveNext() before accessing any
properties.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2
The documentation does not say that. As a matter of fact the Remarks for
Count warns that it is implemented by cloning and walking the nodes which
means the state of the Iterator should not matter. At a minimum that would
be a documentation problem.

However, if you reverse the output lines from RunSelectTest so that MoveNext
is called first you get the same results!

This still looks like an actual bug to me.

Jamie da Silva
Silverlake Software LLC

"Oleg Tkachenko" wrote:
Jamie da Silva wrote:
XPathNodeIterator iter = nav.Select(xpath);
Console.Out.WriteLine("Select Iter Count: {0}",iter.Count);


I believe that's wrong. You must call MoveNext() before accessing any
properties.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com

Nov 12 '05 #3
Hi Jamie,

You're right. The Count property on the iterator returns an incorrect result
for the said query. The upcoming Beta2 release for the next version of the
framework already has a fix for this issue.

Fyi, there is no need to invoke MoveNext() before calling Count on the
iterator.

Regards,
Ion

"Jamie da Silva" <Ja**********@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
The documentation does not say that. As a matter of fact the Remarks for
Count warns that it is implemented by cloning and walking the nodes which
means the state of the Iterator should not matter. At a minimum that would be a documentation problem.

However, if you reverse the output lines from RunSelectTest so that MoveNext is called first you get the same results!

This still looks like an actual bug to me.

Jamie da Silva
Silverlake Software LLC

"Oleg Tkachenko" wrote:
Jamie da Silva wrote:
XPathNodeIterator iter = nav.Select(xpath);
Console.Out.WriteLine("Select Iter Count: {0}",iter.Count);


I believe that's wrong. You must call MoveNext() before accessing any
properties.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com

Nov 12 '05 #4
Thanks Ion. Fortunately it was pretty easy for me to workaround once i found
it.

Jamie da Silva
Silverlake Software LLC

"Ion Vasilian" wrote:
Hi Jamie,

You're right. The Count property on the iterator returns an incorrect result
for the said query. The upcoming Beta2 release for the next version of the
framework already has a fix for this issue.

Fyi, there is no need to invoke MoveNext() before calling Count on the
iterator.

Regards,
Ion

"Jamie da Silva" <Ja**********@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
The documentation does not say that. As a matter of fact the Remarks for
Count warns that it is implemented by cloning and walking the nodes which
means the state of the Iterator should not matter. At a minimum that

would
be a documentation problem.

However, if you reverse the output lines from RunSelectTest so that

MoveNext
is called first you get the same results!

This still looks like an actual bug to me.

Jamie da Silva
Silverlake Software LLC

"Oleg Tkachenko" wrote:
Jamie da Silva wrote:

> XPathNodeIterator iter = nav.Select(xpath);
> Console.Out.WriteLine("Select Iter Count: {0}",iter.Count);

I believe that's wrong. You must call MoveNext() before accessing any
properties.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com


Nov 12 '05 #5

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

Similar topics

0
by: dave | last post by:
I am using the following code to return all items for most rss feeds. This works fine for most however today i came across the following feed where itr (see below) returns nothing....
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...
0
by: Ilian Nilsson | last post by:
Hi Al If I try to use the following code lines in an recursive (recurse down in Xml tree) manner the XPathNodeIterator gets reset in it's parent method call, which will end up in that all nodes...
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...
2
by: Emmanuel | last post by:
Hi, I am writing an ASP.NET web applications which uses an xml file to display html content on the web pages. My problem is that using the Value property of the current object of 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.
0
by: David | last post by:
I'm using an XPathNodeIterator to select an element in an XML document that contains text I am going to put in a label on an aspx page. I want to be able to include HTML tags in the text read from...
2
by: Volkan | last post by:
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...
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.