问题描述
我已经开始在C
中使用libxml
,并且正在使用xmlXPathEvalExpression
函数来评估XPath.
I've started using libxml
in C
, and I'm using the xmlXPathEvalExpression
function to evaluate XPath.
我的XML文件实际上代表一个表,每个子节点代表该表中的一行,并且其属性是对应的值,因此顺序很重要.
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
例如,以下xml文件:
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>
我可以确定在评估/Root/TABLE0/*
并获取节点集之后,调用nodeSet->nodeTab[0]
将获得第一行,nodeSet->nodeTab[1]
将获得第二行,依此类推吗?
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?
谢谢
推荐答案
是的,使用xmlXPathEvalExpression
评估或使用xmlXPathCompile
编译的XPath表达式的结果始终按文档顺序排序. (在内部,通过调用 xmlXPathCompileExpr
带有 true 排序标志.)
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.)
这篇关于libxml xmlXPathEvalExpression顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!