Ramzi Hammouda
Ramzi Hammouda

Reputation: 462

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."

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

Answers (1)

Christian Gr&#252;n
Christian Gr&#252;n

Reputation: 6229

Angle brackets that occur in attributes and text nodes need to be escaped. For attributes, you should use &lt; and &gt;. 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='&lt;Id&gt;CTN53&lt;/ID&gt;'/>
</query>

See e.g. What characters do I need to escape in XML documents? for more examples.

Upvotes: 0

Related Questions