XQuery/比较两个 XML 文件
外观
< XQuery
您想要比较两个 XML 文件。如果文件相同,您希望返回 **true**,否则希望返回 **false**。请注意,如果您想查看差异,请参阅 XQuery/XML 差异 示例。
我们将使用 eXist 中内置的 xdiff:compare() 函数。要使用它,您需要将两个节点传递给 compare 函数
xdiff:compare($node1 as node(), $node2 as node())
假设您有两个不同的 XML 文件
xquery version "1.0";
import module namespace xdiff="http://exist-db.org/xquery/xmldiff" at "java:org.exist.xquery.modules.xmldiff.XmlDiffModule";
let $doc1 := '/db/apps/xml-diffs/data/diff1.xml'
let $doc2 := '/db/apps/xml-diffs/data/diff2.xml'
return
<results>
<result>diff of 1,1: {xdiff:compare(doc($doc1), doc($doc1))}</result>
<result>diff of 1,2: {xdiff:compare(doc($doc1), doc($doc2))}</result>
<result>diff of 2,2: {xdiff:compare(doc($doc2), doc($doc2))}</result>
</results>
结果将是:<syntaxhighlight lang="xml"> <results>
<result>diff of 1,1: true</result> <result>diff of 1,2: false</result> <result>diff of 2,2: true</result>
</results> </source >