简体   繁体   中英

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?

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 eg What characters do I need to escape in XML documents? for more examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM