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

Re: [xml] xpath and the document order



  Hello Liam,

  thank you for comments.

On Fri, 06 May 2005 21:14:01 -0400
"Liam R. E. Quin" <liam holoweb net> wrote:

> On Sat, 2005-05-07 at 01:29 +0400, Oleg A. Paraschenko wrote:
> >   Hello,
> > 
> >   as I understand, the function "xmlXPathEvalExpression" doesn't have
> >   to
> > return nodes in the document order. So here are questions.
> > 
> > 1) Could you show an example of XML and XPath, for which
> >    "xmlXPathEvalExpression" returns nodes not in the document order?
> 
> This most often happens in conjunction with the // operator,
> with alternation (Xpath 2 only) and with the reverse axes such
> as preceding-sibling.

  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
methods to find duplicates is to sort the nodeset, and I suspect that
"xmlXPathEvalExpression" does sort it.

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

[code]
import libxml2

xml = '''
<warning>
<p>
Do <emph>NOT</emph> touch the switch.
The computer will <emph>explode!</emph>
</p>
</warning>
'''
xpath = '/warning//text()'

doc = libxml2.parseDoc(xml)
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval(xpath)

for item in res:
  print "[[%s]]\n" % item.serialize()
[/code]

> 
> > 2) What should be used for sorting a set of nodes:
> > 
> > "xmlXPathNodeSetSort" from "xpath.c" from libxml2, or
> > "xsltDocumentSortFunction" from "xsltutils.c" from libxslt?
> 
> Doesn't it depend whether you are sorting by document order or
> by some other key?

  The both functions use the function "xmlXPathCmpNodes" as the
comparator, so the both functions sort by document order, not
by some other key.

> 
> Liam
> 
> -- 
> Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin
> Pictures from old books: http://www.holoweb.net/~liam/pictures/oldbooks/
> IRC (chat) programs: www.ircreviews.org/clients/
> 


-- 
Oleg Paraschenko  olpa@ http://xmlhack.ru/  XML news in Russian
http://uucode.com/blog/  Generative Programming, XML, TeX, Scheme



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