我创建了一个针对XQuery的http://www.w3schools.com/xsl/books.xml
xquery version "3.0";
for $x in collection("/db/books")//book
return
<book title="{$x/title}">
{$x//author}
</book>如果我在eXistdb的eXide中评估它,就会在预览窗格中得到合理的输出。
<book title="Everyday Italian">
<author>Giada De Laurentiis</author>
etc.如果我试图“运行”它,我将在web浏览器中得到以下错误:
This page contains the following errors:
error on line 4 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
Giada De Laurentiis,我想也许我应该把它序列化为JSON。基于对http://exist-db.org/exist/apps/wiki/blogs/eXist/JSONSerializer的快速阅读,我在xquery版本行之后添加了以下两行:
declare namespace json="http://www.json.org";
declare option exist:serialize "method=json media-type=text/javascript";但是我得到了相同的xml预览结果和相同的浏览器错误。
如何在web浏览器中以XML或JSON的形式获得输出?
我看了https://stackoverflow.com/questions/35038779/json-serialization-with-exist-db-rest-api,但不知道如何使用它作为起点。
发布于 2016-03-17 22:11:43
我很高兴您发现了最初的问题是浏览器需要格式良好的XML,而eXide则乐于向您显示任意节点。
关于JSON序列化的主题,简短地(我正在打电话),请参阅题为“序列化”的部分中的http://exist-db.org/exist/apps/wiki/blogs/eXist/XQuery31。确保您正在运行eXist 3.0 RC1。
发布于 2016-03-17 21:59:08
需要一个顶级标签和一些额外的花括号:
xquery version "3.0";
declare namespace json="http://www.json.org";
declare option exist:serialize "method=json media-type=text/javascript";
<result>
{for $x in collection("/db/books")//book
return
<book title="{$x/title}">
{$x//author}
</book>
}
</result>或者,对于格式良好的XML序列化:
xquery version "3.0";
<result>
{for $x in collection("/db/books")//book
return
<book title="{$x/title}">
{$x//author}
</book>
}
</result>信贷:basics
https://stackoverflow.com/questions/36071544
复制相似问题