libxml xmlXPathEvalExpression order

一曲冷凌霜 提交于 2019-12-11 06:47:05

问题


I've started using libxml in C, and I'm using the xmlXPathEvalExpression function to evaluate XPath.

My XML file actually represents a table, with each child node representing a row in that table and its attributes are the corresponding values, so the order is important.

I couldn't find information about that function in regards to its order. Does it return the nodes in the document order

for example, the following xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <TABLE0>
      <Row Item0="1" Item1="2"/>
      <Row Item0="2" Item1="3"/>
      <Row Item0="3" Item1="4"/>
    </TABLE0>
    <TABLE1>
      <Row Item0="1" Item1="12"/>
      <Row Item0="6" Item1="15"/>
    </TABLE1>
</Root>

Can I be sure that after evaluating /Root/TABLE0/* and getting the nodeset, calling nodeSet->nodeTab[0] would get the first row, nodeSet->nodeTab[1] would get the second and so on?

If not, is there a way to sort it by document order?

Thanks


回答1:


Yes, the results of XPath expressions evaluated with xmlXPathEvalExpression or compiled with xmlXPathCompile are always sorted in document order. (Internally, they're compiled by calling xmlXPathCompileExpr with a true sort flag.)



来源:https://stackoverflow.com/questions/22626947/libxml-xmlxpathevalexpression-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!