[Mono-list] XmlDocument.SelectSingleNode("ancestor::foo")
Piers Haken
piersh@friskit.com
Tue, 4 Mar 2003 15:08:19 -0800
Ouch, good catch Atsushi!
Yeah, it seems that SelectNodes always returns the nodes in document
order, and SelectSingleNode just returns the first of these. Ugh.
Can you add a bug to the database so we can track this, it's not going
to be a simple fix, I'm afraid...
Piers.
-----Original Message-----
From: ginga@kit.hi-ho.ne.jp [mailto:ginga@kit.hi-ho.ne.jp]=20
Sent: Tuesday, March 04, 2003 11:16 AM
To: mono-list@ximian.com
Subject: [Mono-list] XmlDocument.SelectSingleNode("ancestor::foo")
Hi,
I found that mono's XPath feature is incompatible with MS .NET.
XPath specification defines "ancestor" axis as to find ancestor nodes by
"document reversal order." MS's XmlDocument.SelectSingleNode () doesn't,
while Mono's current implementation does.
This method is documented as "always" return a node by document
(non-reversal) order. (I wonder if there are rational reason for them to
break W3C recommendation...)
--------------------
using System;
using System.Xml;
public class Test
{
public static void Main(string[] args) {
XmlDocument doc =3D new XmlDocument ();
doc.LoadXml ("<foo a=3D'1'><foo a=3D'2'><foo a=3D'3'><bar
/></foo></foo></foo>");
XmlElement bar =3D doc.SelectSingleNode ("//bar") as XmlElement;
XmlElement foo =3D bar.SelectSingleNode ("ancestor::foo") as
XmlElement;
Console.WriteLine (foo.GetAttribute ("a"));
foo =3D bar.SelectSingleNode ("ancestor::foo [1]") as XmlElement;
Console.WriteLine (foo.GetAttribute ("a"));
}
}
--------------------
Interesting to say, the last SelectSingleNode("ancestor::foo[1]")
is consistent with XPath recommendation (returns "3").
I cannot say that it is bug of mono, but this inconsistency will be
problematic.
Regards,
Atsushi Eno
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list