문제

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

도움이 되었습니까?

해결책

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top