473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPathNodeIterat or.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 XPathNodeIterat or 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(n ew
StringReader("< root><a></a></root>"));
XPathNavigator nav = doc.CreateNavig ator();

nav.MoveToFirst Child(); // now at "root"
Console.Out.Wri teLine("Current Node Name: {0}\n",nav.Name );

RunSelectTest(n av,"self::root" ,1);
RunSelectTest(n av,"self::nomat ch",2);

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

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

RunSelectTest(n av,"a",7);
RunSelectTest(n av,"nomatch",8) ;

nav.MoveToFirst Child(); // now at "a"

RunSelectTest(n av,"self::a",9) ;
RunSelectTest(n av,"self::nomat ch",10);
}

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

XPathNodeIterat or iter = nav.Select(xpat h);
Console.Out.Wri teLine("Select Iter Count: {0}",iter.Count );
Console.Out.Wri teLine("Select Iter MoveNext: {0}",iter.MoveN ext());
Console.Out.Wri teLine(string.E mpty);
}

Thanks,
Jamie da Silva
Silverlake Software LLC
Nov 12 '05 #1
4 1737
Jamie da Silva wrote:
XPathNodeIterat or iter = nav.Select(xpat h);
Console.Out.Wri teLine("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:
XPathNodeIterat or iter = nav.Select(xpat h);
Console.Out.Wri teLine("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**********@d iscussions.micr osoft.com> wrote in message
news:42******** *************** ***********@mic rosoft.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:
XPathNodeIterat or iter = nav.Select(xpat h);
Console.Out.Wri teLine("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**********@d iscussions.micr osoft.com> wrote in message
news:42******** *************** ***********@mic rosoft.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:

> XPathNodeIterat or iter = nav.Select(xpat h);
> Console.Out.Wri teLine("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
337
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. (http://my.abcnews.go.com/rsspublic/world_rss093.xml) When compared this bad feed with others they appear to have the same structure rss/channel/item Why is itr below returning nothing??? please help
1
8419
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 through a NodeList (e.g.: foreach XmlNode in XmlNodeList ... ) 2. or use an XPathNodeIterator Are there any differences in performance? Are both used for different
0
1417
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 wont be hit. Why is that? Im using 1.1 Framework. If i create an ArrayList containing the nodes from the Iterator and use foreach (instead of the iterator) then it works SomeFunction(oRootNode, "*" Private SomeFunction(aoBaseNode As XmlNode,...
2
3596
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 Book1Book2Book3Book4.. as I understand, func method is called only once and XPathNodeIterator.MoveNext() is called only once..and how is this concatenated output?? tia, avnrao.
2
4567
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 XPathNodeIterator cuts out the embedded html tags. How can I, using an XPathNodeIterator, output the entire contents of a node even if it has child nodes?
3
5328
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
964
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 the XML document, but the XPathNodeIterator.Current.Value property seems to ignore any tags. The text inside the tags is included, but the formatting is not. Is this possible or is there something else I need to do?
2
3825
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 access this iterator's Count property the process extremely slows down. If i just iterate throgh 18.000 nodes and call XPathNavigator.Select to find equivalent node from the other document it doesn't even take 1 second. But in the same loop, when i...
6
7707
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 using an XPathNodeIterator? Or should I be using something else? In the sample that follows: 1. Grab all "Page" nodes. 2. Loop through all the nodes.
0
9688
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
9546
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
10491
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
10247
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,...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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
5467
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
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
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.