473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1700
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.