You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XQuery中无法设置output:method为text格式的问题求助

解决XQuery中文本序列化选项不生效的问题

问题根源

你的代码中序列化选项存在语法错误:declare option output: method "text";里output:和method之间多了空格,不符合XQuery序列化选项的语法规范,导致该选项未被解析生效。查询默认使用XML序列化方式,因此字符串中的<和>被自动转义为&lt;和&gt;。此外,原函数返回离散的字符串项,即使序列化选项生效,也会直接拼接这些项,格式无法匹配预期。

修正后的XQuery代码

declare namespace xf = "http://tempuri.org//test";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";

declare function xf:test($test as element(*)) as item()* {
  for $row in $test/*:row
  return string-join(('"&lt;row&gt;"', '"', data($row), '"'), ",") || "&#10;"
};

declare variable $test as element(*) external;
xf:test($test)

说明

  1. 修正序列化选项语法:将output: method改为output:method,确保文本序列化选项被正确识别,此时XQuery会直接输出字符串内容,不再转义XML特殊字符。
  2. 统一输出格式:使用string-join将每行的多个字符串片段合并为单一字符串,添加&#10;换行符,匹配预期的每行一条记录的格式。

无需依赖Saxon API设置参数,直接运行上述XQuery代码即可得到预期输出:

"<row>","one"
"<row>","two"
"<row>","three"

内容的提问来源于stack exchange,提问作者user29408236

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 14:05:09