[英]Passing < > in xquery with BaseX POST method
I'm Using POST method to update BaseX database, I want to insert an xml node to an existing document calastone.xml in calastone database , if the node contains '<', it returns an error " Line 6): The value of attribute "value" associated with an element type "variable" must not contain the '<' character."我正在使用 POST 方法来更新 BaseX 数据库,我想将一个 xml 节点插入到 Calastone 数据库中的现有文档 Calastone.xml 中,如果该节点包含“<”,则返回错误“第 6 行):属性值与元素类型“变量”关联的“值”不得包含“<”字符。”
code:代码:
<query>
<text>
let $message := '<Id>CTN53</Id>'
return insert nodes $message as last into doc("calastone/calastone.xml")
</text>
<variable name='message' value='<Id>CTN53</ID>'/>
</query>
the same code without '<' adds the text correctly.没有“<”的相同代码正确添加了文本。
how to solve this problem?如何解决这个问题呢?
Angle brackets that occur in attributes and text nodes need to be escaped.出现在属性和文本节点中的尖括号需要转义。 For attributes, you should use <
对于属性,您应该使用<
and >
和>
. . For text nodes, CDATA sections are often more convenient:对于文本节点,CDATA 部分通常更方便:
<query>
<text><![CDATA[
let $message := '<Id>CTN53</Id>'
return insert nodes $message as last into doc("calastone/calastone.xml")
]]></text>
<variable name='message' value='<Id>CTN53</ID>'/>
</query>
See eg What characters do I need to escape in XML documents?参见例如我需要在 XML 文档中转义哪些字符? for more examples.更多例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.