Order libxml xmlXPathEvalExpression

I started using libxml in C , and I use the xmlXPathEvalExpression function to evaluate XPath.

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

I could not find information about this function regarding its order. Does it return 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 receiving a set of nodes, the call to nodeSet->nodeTab[0] will get the first line, nodeSet->nodeTab[1] will get the second, and so on?

If not, is there a way to sort it in the order of the document?

thanks

+1
source share
1 answer

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

+3
source

Source: https://habr.com/ru/post/969960/


All Articles