Xquery 函数 parse-xml() 在 &?

Xquery the function parse-xml() produces an error on &?

作为 HTTP POST 请求中的 XML 内容,我收到以下我在 Xquery 3.1 (eXist-db 5.2) 中处理的内容:

<request id="foo">
     <p>The is a description with a line break&lt;br/&gt;and another linebreak&lt;br/&gt;and
            here is an ampersand&amp;.</p>
<request>

我的objective 是获取节点<p> 并将其插入到eXist-db 中的TEI 文件中。如果我按原样插入片段,则不会抛出任何错误。

但是,在将其添加到 TEI 文档之前,我需要将字符串 &lt;br/&gt; 的任何实例转换为元素 <lb/>。我尝试使用 fn:parse-xml.

但是,应用以下内容会在 &amp 上引发错误...这让我感到惊讶:

let $xml := <request id="foo">
                 <p>The is a description with a line break&lt;br/&gt;and 
                    another linebreak&lt;br/&gt;and here is an ampersand&amp;.</p>
           <request>
let $newxml := <p>{replace($xml//p/text(),"&lt;br/&gt;","&lt;lb/&gt;")}</p>
return <p>{fn:parse-xml($newxml)}</p>

错误:

Description: err:FODC0006 String passed to fn:parse-xml is not a well-formed XML document.: Document is not valid.
Fatal : The entity name must immediately follow the '&' in the entity reference.

如果我删除 &amp; 片段解析就好了。如果它是合法的 XML,为什么会产生错误?我怎样才能达到所需的结果?

非常感谢。

ps。我对 Xquery 和 XSLT 解决方案持开放态度。

问题似乎出在 HTML 个实体上。它适用于数字实体(即 &#60; 而不是 &lt;&#62; 而不是 &gt;),但是 XML 解析器不知道 HTML字符实体。

使用util:parse-html()代替fn:parse-xml()

let $xml := <request id="foo">
                  <p>The is a description with a line break&lt;br/&gt;and 
                    another linebreak&lt;br/&gt;and here is an ampersand&amp;.</p>
           </request>
return <p>{util:parse-html($xml/p/text())/HTML/BODY/node()}</p>