Reputation: 462
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."
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?
Upvotes: 0
Views: 144
Reputation: 6229
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:
<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 e.g. What characters do I need to escape in XML documents? for more examples.
Upvotes: 0