XPath query result order

后端 未结 5 463
心在旅途
心在旅途 2020-12-02 02:00

For another question I have created some XML related code that works on my development machine but not on viper codepad where I tested it before adding it to my answer.

相关标签:
5条回答
  • 2020-12-02 02:23

    I could find the following bug-report which looks like the issue: Bug 363252 - proximity position in libxml2's xmlXPathEvalExpression() reported 18 Oct 2006 and confirmed dating back since May 2006 which is before the 2.6.26 version in question.

    This should have been fixed in libxml2 2.6.27.

    0 讨论(0)
  • 2020-12-02 02:29

    Technically XPath 1.0 returns node-sets rather than node sequences. In the XPath 1.0 specification there is no statement about the order of these node-sets - indeed, being sets, they have no intrinsic order.

    However, XSLT 1.0 always processes the node-sets returned by XPath 1.0 in document order, and because of that precedent, there is a widespread expectation that XPath results will be in document order when XPath is invoked from languages other than XSLT. However, there is nothing in the spec to guarantee this. In XPath 2.0 the user expectation becomes part of the spec, and the results of a path expression MUST be in document order.

    0 讨论(0)
  • 2020-12-02 02:35

    It appears that Viper Codepad is not returning the selected text() nodes in depth first document order, but doing a breadth first evaluation.

    It is supposed to be a depth first traversal.

    Saxon, MSXML, Altova XML each returned the results in a depth-first order.

    0 讨论(0)
  • 2020-12-02 02:39

    It looks like an bug in 20626 version:

    It process first all child text nodes in document order, then content of child element nodes. Should be as result on your machine

    0 讨论(0)
  • 2020-12-02 02:40

    XPath is a query language, thus it should only read the structure of the .xml document as is and never modify it. This includes the node order. In your first example however this is not true. So this is definitely a bug according to this.

    0 讨论(0)
提交回复
热议问题