insert an xml structure in database
Monday, 11 April 2016 · 3 messages · last reply 12 Apr 2016
OD
Oleg Duvanayev11 Apr 2016 19:37 #
dear lady and gentlemen,
i have to add in a test database the simple document. I use the database, which is running as web-application in tomcat and access to database i do with REST. I tried to use this approatch, but it doesn't work for me. I take always the message "Bad request":
In the attachment you find the method i use to take a resonse from database.
I am really sorry, i can find solution. Could you please assist me to solve this issue ?
The second missunderstanding is the description of commands.
how can i use in my case for example "XML Syntax" ?
very many thanks for any help
best regards
Oleg Duvanayev
CG
Christian Grün12 Apr 2016 08:38 #
Hi Oleg,
Two things need to be considered to make your code work:
* Please have a closer look at the syntax of the ADD command. The "TO" keyword is required to indicate that you are also specifying a database path. This is how it should be: add to /kgw <book id="1" />
* If you enclose a command string with XML snippets, it needs to be encoded (otherwise, XML will really be interpreted as XML, even before the command will be interpreteed in a second step):
OLD:
<text><![CDATA[ add to /kgw <book id=\"1\" /> ]]></text>
Correct (1st variant):
<text> add to /kgw <book id=\"1\" /> </text>
Correct (2nd variant):
<text><![CDATA[ add to /kgw <book id=\"1\" /> ]]></text>
If you want to add XML via REST, it is probably easier, and faster, to use the PUT method [1,2]. It allows you to both create new databases and add/update its resources (and there will be no need to encode your XML stream).
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/REST#PUT_Method
[2] https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/rest/RESTPut.java
Quoted text · Oleg Duvanayev · 21 lines
On Mon, Apr 11, 2016 at 7:37 PM, Oleg Duvanayev <duvanaev at gmx.net> wrote: > > dear lady and gentlemen, > > i have to add in a test database the simple document. I use the database, which is running as web-application in tomcat and access to database i do with REST. I tried to use this approatch, but it doesn't work for me. I take always the message "Bad request": > > > In the attachment you find the method i use to take a resonse from database. > > I am really sorry, i can find solution. Could you please assist me to solve this issue ? > > The second missunderstanding is the description of commands. > > > how can i use in my case for example "XML Syntax" ? > > very many thanks for any help > best regards > Oleg Duvanayev > >
OD
Oleg Duvanayev12 Apr 2016 10:26 #
hi Christian,
very many thanks
best regards
Gesendet: Dienstag, 12. April 2016 um 08:38 Uhr
Quoted text · Christian Grün · 47 lines
Von: "Christian Grün" <christian.gruen at gmail.com> An: "Oleg Duvanayev" <duvanaev at gmx.net> Cc: BaseX <basex-talk at mailman.uni-konstanz.de> Betreff: Re: [basex-talk] insert an xml structure in database Hi Oleg, Two things need to be considered to make your code work: * Please have a closer look at the syntax of the ADD command. The "TO" keyword is required to indicate that you are also specifying a database path. This is how it should be: add to /kgw <book id="1" /> * If you enclose a command string with XML snippets, it needs to be encoded (otherwise, XML will really be interpreted as XML, even before the command will be interpreteed in a second step): OLD: <text><![CDATA[ add to /kgw <book id=\"1\" /> ]]></text> Correct (1st variant): <text> add to /kgw <book id=\"1\" /> </text> Correct (2nd variant): <text><![CDATA[ add to /kgw <book id=\"1\" /> ]]></text> If you want to add XML via REST, it is probably easier, and faster, to use the PUT method [1,2]. It allows you to both create new databases and add/update its resources (and there will be no need to encode your XML stream). Hope this helps, Christian [1] http://docs.basex.org/wiki/REST#PUT_Method [2] https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/org/basex/examples/rest/RESTPut.java On Mon, Apr 11, 2016 at 7:37 PM, Oleg Duvanayev <duvanaev at gmx.net> wrote: > > dear lady and gentlemen, > > i have to add in a test database the simple document. I use the database, which is running as web-application in tomcat and access to database i do with REST. I tried to use this approatch, but it doesn't work for me. I take always the message "Bad request": > > > In the attachment you find the method i use to take a resonse from database. > > I am really sorry, i can find solution. Could you please assist me to solve this issue ? > > The second missunderstanding is the description of commands. > > > how can i use in my case for example "XML Syntax" ? > > very many thanks for any help > best regards > Oleg Duvanayev > >
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery