Storing xml message
Tuesday, 21 April 2020 · 3 messages · last reply 8 May 2020
RH
Ramzi Hammouda21 Apr 2020 12:33 #
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, Link<https://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.
OS
Omar Siam21 Apr 2020 14:09 #
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.
Quoted text · Ramzi Hammouda · 51 lines
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, Link > <https://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./
RH
Ramzi Hammouda8 May 2020 16:36 #
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.
Quoted text · BaseX-Talk · 24 lines
From: BaseX-Talk <basex-talk-bounces at mailman.uni-konstanz.de> On Behalf Of Omar Siam Sent: mardi 21 avril 2020 13:09 To: basex-talk at 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, Link<https://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.
Written for BaseX 9.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery