[Mono-list] XmlDocument.SelectSingleNode("ancestor::foo")

ginga@kit.hi-ho.ne.jp ginga@kit.hi-ho.ne.jp
Wed, 05 Mar 2003 04:15:38 +0900


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 = new XmlDocument ();
    doc.LoadXml ("<foo a='1'><foo a='2'><foo a='3'><bar
    XmlElement bar = doc.SelectSingleNode ("//bar") as XmlElement;
    XmlElement foo = bar.SelectSingleNode ("ancestor::foo") as
    Console.WriteLine (foo.GetAttribute ("a"));

    foo = 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.

  Atsushi Eno