Re: [xml] xpath and the document order

On Sun, May 08, 2005 at 12:11:58AM +0400, Oleg A. Paraschenko wrote:
  I tried different combinations, but failed and gave up. Maybe it's
because I don't believe that I can find an example. As far as I know,
a result nodeset shouldn't contain duplicates. One of the simplest

  yes that is garanteed.

methods to find duplicates is to sort the nodeset, and I suspect that
"xmlXPathEvalExpression" does sort it.

  Duplicates are eleminated when growing the node set. 

  But maybe I just use an incorrect code to test. Here it is:

xpath = '/warning//text()'

  You can use testXPath to see how this is compiled:

paphio:~/XML -> ./testXPath --tree '/warning//text()'
Compiled Expression : 5 elements
    COLLECT  'child' 'type' 'text' text
      COLLECT  'descendant-or-self' 'type' 'node'
        COLLECT  'child' 'name' 'node' warning

  by default the XPath compiler adds a sorting step. So it seems 
you were right, xmlXPathEvalExpression will order the output at least
in that case. One way to force ordering at the XPath level is to
put the XPath expression between curly braces: "(your_xpath_here)"


Daniel Veillard      | Red Hat Desktop team
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]