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

BaseX REST接口执行XQuery查询时出现"Extra content at the end of the document"错误的求助

Fixing "Extra content at the end of the document" Error in BaseX REST Queries

I ran into a similar issue with BaseX's REST API a while back—here's what's going on and how to fix it:

The Root Cause

When you run number() or string() directly in the BaseX client, it just outputs the atomic value (like 10 or FirstOwner) without needing to wrap it in valid XML. But the BaseX REST interface defaults to returning XML documents, which require exactly one root element. Returning a raw number/string violates this XML structure rule, hence the "Extra content at the end of the document" error.

Solution 1: Wrap Your Result in an XML Element

Modify your query to wrap the atomic value inside a single root element. This makes the output a valid XML document that the REST interface can return without issues.

For example, to get the owner ID:

http://localhostadress:port/rest/database_name?query=<result>{number(/config/datas/data_owner[@name="FirstOwner"]/@id)}</result>

To get the owner name:

http://localhostadress:port/rest/database_name?query=<result>{string(/config/datas/data_owner[@id=10]/@name)}</result>

This will return a valid XML response like <result>10</result> or <result>FirstOwner</result>.

Solution 2: Force Text Output Mode

If you don't want XML wrapping at all, you can tell the REST API to return plain text instead of XML by adding the method=text parameter to your URL.

For the owner ID query:

http://localhostadress:port/rest/database_name?method=text&query=number(/config/datas/data_owner[@name="FirstOwner"]/@id)

For the owner name query:

http://localhostadress:port/rest/database_name?method=text&query=string(/config/datas/data_owner[@id=10]/@name)

This will return just the raw value (10 or FirstOwner) as plain text, no XML structure required.

Either of these approaches should resolve the error you're seeing.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 07:07:31