【问题标题】:BaseX XQuery replaceBaseX XQuery 替换
【发布时间】:2012-11-28 09:28:43
【问题描述】:

我有以下问题。我想通过使用 baseX 作为数据库来替换我的 xquery 文件中的一个元素的值。 xquery代码如下:

    let $db := doc('update.xml')

replace value of node $db//elem with 'haha'

return <result> {$db//elem/text()} </result>

xml 文档包含以下元素:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<check>
    <ok>
        <elem>test</elem>
        <help></help>
    </ok>
</check>
</root> 

每次我想执行这个 xquery 时都会抛出这样的错误:

Expecting 'where', 'order' or 'return' expression

那么我应该怎么做或改变,只是将元素中的文本“test”替换为“haha”? 如果我只使用这行代码它可以工作,但我必须读出 URL-Parameter 所以我需要更多的代码行,除了“replace ....”行!

【问题讨论】:

    标签: replace xquery basex xquery-update


    【解决方案1】:

    let 启动一个可能不直接包含更新语句的 flwor 表达式。您必须在这两者之间添加一个return:

    let $db := doc('update.xml')
    return
      replace value of node $db//elem with 'haha'
    

    您还可以进行任意计算,但请确保您的查询不会返回任何输出。

    没有way to use updating statements and return a result at the same time。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多