Thanks for the reply,
I tried using the function fn:parse-xml, I had success with using it in BaseX GUI like this:
let $message := fn:parse-xml('<Id>CTN55</Id>') return insert nodes $message as last into doc("calastone/calastone.xml")
But when I tried to do the same with POST API method from my application with using this xquery:
string xquery = "<query><text>let $message:= fn:parse-xml('<Id>CTN58</Id>')" + "return insert nodes $message as last into doc("calastone/calastone.xml")</text>" + "<variable name = 'message' value = fn:parse-xml('<Id>CTN58</Id>'))/></query>";
I get the error: "" (Line 1): Element type "variable" must be followed by either attribute specifications, ">" or "/>"
Can you help on how to do this insertion?
Thanks.
From: BaseX-Talk basex-talk-bounces@mailman.uni-konstanz.de On Behalf Of Omar Siam Sent: mardi 21 avril 2020 13:09 To: basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] Storing xml message
If you pass some XML in to your query as text (because that is the only thing you can have inside an attribute) you have to do a parse-xml (or parse-xml-fragment if its more like a sequence) and insert that. Am 21.04.2020 um 12:33 schrieb Ramzi Hammouda: Hello, First, thanks for the effort you're putting it to help BaseX users.
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? Note that this is a question I posted on Stackoverflow, Linkhttps://stackoverflow.com/questions/60456387/passing-in-xquery-with-basex-post-method/60456826?noredirect=1#comment106958333_60456826. Christian Grun suggested using < and > for attributes and CDATA for text nodes. After applying that solution, the xml stored is in this form <Id>CTN53</Id> This is not what I'm looking for. Is there any other more convenient solutions to store XML messages with Rest APIs? I know PUT method works fine but it overwrites the content of the document. Thank you.
P Respectons ensemble l'environnement. N'imprimez ce message que si nécessaire. Let's respect the environment together. Only print this message if necessary.