有没有一种简单的方法可以使用Zorba处理器来更新多个XQuery文件,并将修改的输出保存回同一个文件中?
到目前为止,我已经了解了如何使用File模块和file:list扩展来查找目录中的所有XML文件来处理多个文件。然后,我遍历每个文档并运行XQuery更新语句(将节点{}的值替换为{})。问题是,这实际上并没有修改文件。
我之前使用的是Saxon,但是许可成本对于这个特定的项目来说太贵了。在Saxon EE中,如果我在一个打开的文档上运行"replace value of node“,那么当查询完成时,该文档将在磁盘上更新。我怀疑Zorba不是这样工作的,而是在查询期间只修改内存中的值。如果我正在编辑一个文件,我将只在Zorba中输出修改后的XML,并通过管道将其返回到输入文件,但在本例中,我希望更新许多文件。这可以在一个查询中实现吗?
下面是代码的样子:
import module namespace file = "http://expath.org/ns/file";
for $file in file:list("XML", true(), "*.xml")
let $doc := doc(concat("XML/", $file))
return
{
for $key in $doc//key
return
replace value of node $key/texture
with replace($key/material/text(), ".mat", ".png")
}发布于 2013-08-15 02:19:33
想明白了!我不得不使用Zorba提供的XQuery脚本扩展将结果重写回文件:
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
import module namespace file = "http://expath.org/ns/file";
for $file in file:list("XML", true(), "*.xml")
return
{
variable $doc := doc(concat("XML/", $file));
for $key in $doc//key
return
replace value of node $key/texture
with replace($key/material/text(), ".mat", ".png");
file:write(concat("XML/", $file), $doc,
<output:serialization-parameters>
<output:indent value="yes"/>
<output:method value="xml"/>
<output:omit-xml-declaration value="no"/>
</output:serialization-parameters>
);
}https://stackoverflow.com/questions/18237516
复制相似问题