Command line options not working with update operation on input file
Friday, 7 December 2018 · 15 messages · last reply 13 Dec 2018
ZD
Zimmel, Daniel7 Dec 2018 15:40 #
Hello,
can anyone give me a hint on the behaviour of the command line options in BaseX 9.0.2?
When I try an update operation on a file given with "-i", neither the option "-w" nor any serialisation option gets evaluated; while the update operation with "-u" is working correctly, my whitespace gets happily chopped.
CCL:
$ basex.bat -ifile.xml -sindent=no -u -w update.xquery
XQ:
for $c in doc(document-uri())//element
return replace value of node $c with "TEST"A workaround is using fetch:xml() with document-uri(), which does leave any whitespace intact and does no indentation (no parameters necessary).
declare variable $doc := document-uri();
for $c in fetch:xml($doc)//element
return replace value of node $c with "TEST"Unfortunately my requirement is I cannot use specific BaseX-functions in this specific update script.
My XML:
<root>
<vs>
<kennung>Kennung</kennung>
<absatz> <fett>eins</fett>
</absatz>
<absatz id="sgb04_k_para067_p67_a0001_a0001"> Test <fett>fett</fett> <kursiv>kursiv</kursiv> Text Text.</absatz>
</vs>
</root>Thanks, Daniel
CG
Christian Grün7 Dec 2018 17:40 #
Hi Daniel.
The argument order is important in BaseX; you could try the following variant:
basex.bat -u -w -ifile.xml -sindent=no update.xqueryIf this doesn’t help, you could append the CHOP=true in your .basex configuration file.
Hope this helps
Christian
Quoted text · Daniel · 37 lines
On Fri, Dec 7, 2018 at 3:40 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> wrote: > > Hello, > > can anyone give me a hint on the behaviour of the command line options in BaseX 9.0.2? > > When I try an update operation on a file given with "-i", neither the option "-w" nor any serialisation option gets evaluated; while the update operation with "-u" is working correctly, my whitespace gets happily chopped. > > CCL: > $ basex.bat -ifile.xml -sindent=no -u -w update.xquery > > XQ: > for $c in doc(document-uri())//element > return replace value of node $c with "TEST" > > A workaround is using fetch:xml() with document-uri(), which does leave any whitespace intact and does no indentation (no parameters necessary). > > declare variable $doc := document-uri(); > for $c in fetch:xml($doc)//element > return replace value of node $c with "TEST" > > Unfortunately my requirement is I cannot use specific BaseX-functions in this specific update script. > > My XML: > > <root> > <vs> > <kennung>Kennung</kennung> > <absatz> <fett>eins</fett> > </absatz> > <absatz id="sgb04_k_para067_p67_a0001_a0001"> Test <fett>fett</fett> <kursiv>kursiv</kursiv> Text Text.</absatz> > </vs> > </root> > > Thanks, Daniel > >
ZD
Zimmel, Daniel10 Dec 2018 11:28 #
Thank you Christian, changing the argument order does help indeed with the whitespace! The documentation is slightly vague about this.
Unfortunately, I still have not found a way to force BaseX NOT to delete my xml declaration with any update operation on a given input file. For example if I use the same operation in Oxygen, not omitting the declaration is the default behaviour in Saxon EE.
But with BaseX, while I could use
fn:put() with a map of serialisation parameters in the return statement, this does not help much because I can not use BaseX functions in my script :-( Is changing this (default) outside the scope of an update script not possible?
BTW I noticed some strange behaviour (this is possibly a bug?)
- when CHOP=false in the .basex file and -w switch not set, whitespace does not get chopped (expected)
- when CHOP=false in the .basex file and -w switch on the command line, whitespace gets chopped (not expected!)
Thanks, DanielQuoted text · Christian Grün · 66 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Freitag, 7. Dezember 2018 17:41 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > Hi Daniel. > > The argument order is important in BaseX; you could try the following variant: > > basex.bat -u -w -ifile.xml -sindent=no update.xquery > > If this doesn’t help, you could append the CHOP=true in your .basex > configuration file. > > Hope this helps > Christian > > > > On Fri, Dec 7, 2018 at 3:40 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> > wrote: > > > > Hello, > > > > can anyone give me a hint on the behaviour of the command line options in > BaseX 9.0.2? > > > > When I try an update operation on a file given with "-i", neither the option "-w" > nor any serialisation option gets evaluated; while the update operation with "-u" is > working correctly, my whitespace gets happily chopped. > > > > CCL: > > $ basex.bat -ifile.xml -sindent=no -u -w update.xquery > > > > XQ: > > for $c in doc(document-uri())//element > > return replace value of node $c with "TEST" > > > > A workaround is using fetch:xml() with document-uri(), which does leave any > whitespace intact and does no indentation (no parameters necessary). > > > > declare variable $doc := document-uri(); > > for $c in fetch:xml($doc)//element > > return replace value of node $c with "TEST" > > > > Unfortunately my requirement is I cannot use specific BaseX-functions in this > specific update script. > > > > My XML: > > > > <root> > > <vs> > > <kennung>Kennung</kennung> > > <absatz> <fett>eins</fett> > > </absatz> > > <absatz id="sgb04_k_para067_p67_a0001_a0001"> Test <fett>fett</fett> > <kursiv>kursiv</kursiv> Text Text.</absatz> > > </vs> > > </root> > > > > Thanks, Daniel > > > >
CG
Christian Grün12 Dec 2018 17:04 #
Hi Daniel,
Quoted text · Zimmel, Daniel · 1 line
> Unfortunately, I still have not found a way to force BaseX NOT to delete my xml declaration with any update operation on a given input file.
The XML declaration is a part of the serialization process. You can enable it by adding…
SERIALIZER=omit-xml-declaration=no,indent=no
…to your .basex configuration file. I have added indent=no, as this is usually the best option when preserving whitespaces.
Quoted text · Zimmel, Daniel · 1 line
> - when CHOP=false in the .basex file and -w switch on the command line, whitespace gets chopped (not expected!)
The command-line help should probably be revised. With -w, the value of the option is actually toggled. I have updated our documentation to make this more obvious [1]. You can use -v to see which value will be assigned.
Best,
Christian
[1] http://docs.basex.org/wiki/Command-Line_Options
Quoted text · Zimmel, Daniel · 66 lines
> > -----Ursprüngliche Nachricht----- > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > Gesendet: Freitag, 7. Dezember 2018 17:41 > > An: Zimmel, Daniel > > Cc: BaseX > > Betreff: Re: [basex-talk] Command line options not working with update operation > > on input file > > > > Hi Daniel. > > > > The argument order is important in BaseX; you could try the following variant: > > > > basex.bat -u -w -ifile.xml -sindent=no update.xquery > > > > If this doesn’t help, you could append the CHOP=true in your .basex > > configuration file. > > > > Hope this helps > > Christian > > > > > > > > On Fri, Dec 7, 2018 at 3:40 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> > > wrote: > > > > > > Hello, > > > > > > can anyone give me a hint on the behaviour of the command line options in > > BaseX 9.0.2? > > > > > > When I try an update operation on a file given with "-i", neither the option "-w" > > nor any serialisation option gets evaluated; while the update operation with "-u" is > > working correctly, my whitespace gets happily chopped. > > > > > > CCL: > > > $ basex.bat -ifile.xml -sindent=no -u -w update.xquery > > > > > > XQ: > > > for $c in doc(document-uri())//element > > > return replace value of node $c with "TEST" > > > > > > A workaround is using fetch:xml() with document-uri(), which does leave any > > whitespace intact and does no indentation (no parameters necessary). > > > > > > declare variable $doc := document-uri(); > > > for $c in fetch:xml($doc)//element > > > return replace value of node $c with "TEST" > > > > > > Unfortunately my requirement is I cannot use specific BaseX-functions in this > > specific update script. > > > > > > My XML: > > > > > > <root> > > > <vs> > > > <kennung>Kennung</kennung> > > > <absatz> <fett>eins</fett> > > > </absatz> > > > <absatz id="sgb04_k_para067_p67_a0001_a0001"> Test <fett>fett</fett> > > <kursiv>kursiv</kursiv> Text Text.</absatz> > > > </vs> > > > </root> > > > > > > Thanks, Daniel > > > > > >
ZD
Zimmel, Daniel12 Dec 2018 18:20 #
I already tried setting serialization params in .basex, per command line switch and as declare variable. Any serialization parameter gets ignored from the command line with XQuery Update.
I found an ancient report about this behaviour in the archives, but no solution: https://mailman.uni-konstanz.de/pipermail/basex-talk/2011-May/001593.html
Has this been solved? Is this a bug?
What does work is using
fn:put() with writing to document-uri() and supplying a serialization map as third parameter. Unfortunately, for unknown reasons Saxon fails with a third parameter for fn:put(), even with XQuery 3.1 enabled (the BaseX implementation seems more correct after reading the specification). Right now, I would need a variant when I want to run my script in both BaseX commandline and Oxygen with Saxon EE.
DanielQuoted text · Christian Grün · 107 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Mittwoch, 12. Dezember 2018 17:04 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > Hi Daniel, > > > Unfortunately, I still have not found a way to force BaseX NOT to delete my xml > declaration with any update operation on a given input file. > > The XML declaration is a part of the serialization process. You can > enable it by adding… > > SERIALIZER=omit-xml-declaration=no,indent=no > > …to your .basex configuration file. I have added indent=no, as this is > usually the best option when preserving whitespaces. > > > - when CHOP=false in the .basex file and -w switch on the command line, > whitespace gets chopped (not expected!) > > The command-line help should probably be revised. With -w, the value > of the option is actually toggled. I have updated our documentation to > make this more obvious [1]. You can use -v to see which value will be > assigned. > > Best, > Christian > > [1] http://docs.basex.org/wiki/Command-Line_Options > > > > > -----Ursprüngliche Nachricht----- > > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > > Gesendet: Freitag, 7. Dezember 2018 17:41 > > > An: Zimmel, Daniel > > > Cc: BaseX > > > Betreff: Re: [basex-talk] Command line options not working with update > operation > > > on input file > > > > > > Hi Daniel. > > > > > > The argument order is important in BaseX; you could try the following variant: > > > > > > basex.bat -u -w -ifile.xml -sindent=no update.xquery > > > > > > If this doesn’t help, you could append the CHOP=true in your .basex > > > configuration file. > > > > > > Hope this helps > > > Christian > > > > > > > > > > > > On Fri, Dec 7, 2018 at 3:40 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> > > > wrote: > > > > > > > > Hello, > > > > > > > > can anyone give me a hint on the behaviour of the command line options in > > > BaseX 9.0.2? > > > > > > > > When I try an update operation on a file given with "-i", neither the option "- > w" > > > nor any serialisation option gets evaluated; while the update operation with "- > u" is > > > working correctly, my whitespace gets happily chopped. > > > > > > > > CCL: > > > > $ basex.bat -ifile.xml -sindent=no -u -w update.xquery > > > > > > > > XQ: > > > > for $c in doc(document-uri())//element > > > > return replace value of node $c with "TEST" > > > > > > > > A workaround is using fetch:xml() with document-uri(), which does leave > any > > > whitespace intact and does no indentation (no parameters necessary). > > > > > > > > declare variable $doc := document-uri(); > > > > for $c in fetch:xml($doc)//element > > > > return replace value of node $c with "TEST" > > > > > > > > Unfortunately my requirement is I cannot use specific BaseX-functions in > this > > > specific update script. > > > > > > > > My XML: > > > > > > > > <root> > > > > <vs> > > > > <kennung>Kennung</kennung> > > > > <absatz> <fett>eins</fett> > > > > </absatz> > > > > <absatz id="sgb04_k_para067_p67_a0001_a0001"> Test > <fett>fett</fett> > > > <kursiv>kursiv</kursiv> Text Text.</absatz> > > > > </vs> > > > > </root> > > > > > > > > Thanks, Daniel > > > > > > > >
CG
Christian Grün12 Dec 2018 18:35 #
Quoted text · Zimmel, Daniel · 3 lines
> Any serialization parameter gets ignored from the command line with XQuery Update. > > Has this been solved? Is this a bug?
XML declarations are never stored in the database. Instead, they will be added during serialization. So I’m not exactly on what you just tried to do. Could you please give some step-by-step instructions?
CG
Christian Grün12 Dec 2018 18:47 #
…I think I got what you were trying to achieve! There is a separate option for exporting databases and writing updates. This may be more obvious now after another updates of our documentation [1].
Here is a little self-contained BaseX call that (as I hope)
demonstrates the behavior:
basex -u -c"set exporter omit-xml-declaration=no"
"
file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" "fetch:xml('doc.xml')"<?xml version="1.0" encoding="UTF-8"?>
<a>
<b/>
</a>You can also run the following command script ("basex script.bxs"):
set exporter omit-xml-declaration=no
set writeback on
xquery file:write('doc.xml', <a/>)
xquery insert node <a/> into doc('doc.xml')/*
xquery fetch:xml('doc.xml')Maybe we’ll merge these two options in a future release of BaseX. Until then, just add an
EXPORTER option to your .basex file with the identical serialization parameters.
Best
Christian
[1] http://docs.basex.org/wiki/Options#WRITEBACKQuoted text · Christian Grün · 10 lines
On Wed, Dec 12, 2018 at 6:35 PM Christian Grün <christian.gruen at gmail.com> wrote: > > > Any serialization parameter gets ignored from the command line with XQuery Update. > > > > Has this been solved? Is this a bug? > > XML declarations are never stored in the database. Instead, they will > be added during serialization. So I’m not exactly on what you just > tried to do. Could you please give some step-by-step instructions?
ZD
Zimmel, Daniel13 Dec 2018 12:16 #
Ah, now this makes it much more clear in the documentation, I just checked the wiki page history.
The only thing is I prefer the Saxon default about not changing anything on already existing indentation (BaseX is deleting any indentation with indent=no), but I am aware this is implementation-defined.
Thanks for the update,
Daniel
Quoted text · Christian Grün · 55 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Mittwoch, 12. Dezember 2018 18:47 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > …I think I got what you were trying to achieve! There is a separate > option for exporting databases and writing updates. This may be more > obvious now after another updates of our documentation [1]. > > Here is a little self-contained BaseX call that (as I hope) > demonstrates the behavior: > > basex -u -c"set exporter omit-xml-declaration=no" > "file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" > "fetch:xml('doc.xml')" > > <?xml version="1.0" encoding="UTF-8"?> > <a> > <b/> > </a> > > You can also run the following command script ("basex script.bxs"): > > set exporter omit-xml-declaration=no > set writeback on > xquery file:write('doc.xml', <a/>) > xquery insert node <a/> into doc('doc.xml')/* > xquery fetch:xml('doc.xml') > > Maybe we’ll merge these two options in a future release of BaseX. > Until then, just add an EXPORTER option to your .basex file with the > identical serialization parameters. > > Best > Christian > > [1] http://docs.basex.org/wiki/Options#WRITEBACK > > > > > On Wed, Dec 12, 2018 at 6:35 PM Christian Grün > <christian.gruen at gmail.com> wrote: > > > > > Any serialization parameter gets ignored from the command line with XQuery > Update. > > > > > > Has this been solved? Is this a bug? > > > > XML declarations are never stored in the database. Instead, they will > > be added during serialization. So I’m not exactly on what you just > > tried to do. Could you please give some step-by-step instructions?
CG
Christian Grün13 Dec 2018 12:41 #
Quoted text · Zimmel, Daniel · 1 line
> The only thing is I prefer the Saxon default about not changing anything on already existing indentation (BaseX is deleting any indentation with indent=no), but I am aware this is implementation-defined.
Existing identation is actually preserved by both BaseX and Saxon:
declare namespace output = 'http://www.w3.org/2010/xslt-xquery-serialization';
declare option output:indent 'no';
parse-xml('<a>
<b/>
</a>')Were you referring to documents with chopped whitespaces?
Cheers
Christian
Quoted text · Zimmel, Daniel · 55 lines
> > -----Ursprüngliche Nachricht----- > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > Gesendet: Mittwoch, 12. Dezember 2018 18:47 > > An: Zimmel, Daniel > > Cc: BaseX > > Betreff: Re: [basex-talk] Command line options not working with update operation > > on input file > > > > …I think I got what you were trying to achieve! There is a separate > > option for exporting databases and writing updates. This may be more > > obvious now after another updates of our documentation [1]. > > > > Here is a little self-contained BaseX call that (as I hope) > > demonstrates the behavior: > > > > basex -u -c"set exporter omit-xml-declaration=no" > > "file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" > > "fetch:xml('doc.xml')" > > > > <?xml version="1.0" encoding="UTF-8"?> > > <a> > > <b/> > > </a> > > > > You can also run the following command script ("basex script.bxs"): > > > > set exporter omit-xml-declaration=no > > set writeback on > > xquery file:write('doc.xml', <a/>) > > xquery insert node <a/> into doc('doc.xml')/* > > xquery fetch:xml('doc.xml') > > > > Maybe we’ll merge these two options in a future release of BaseX. > > Until then, just add an EXPORTER option to your .basex file with the > > identical serialization parameters. > > > > Best > > Christian > > > > [1] http://docs.basex.org/wiki/Options#WRITEBACK > > > > > > > > > > On Wed, Dec 12, 2018 at 6:35 PM Christian Grün > > <christian.gruen at gmail.com> wrote: > > > > > > > Any serialization parameter gets ignored from the command line with XQuery > > Update. > > > > > > > > Has this been solved? Is this a bug? > > > > > > XML declarations are never stored in the database. Instead, they will > > > be added during serialization. So I’m not exactly on what you just > > > tried to do. Could you please give some step-by-step instructions?
ZD
Zimmel, Daniel13 Dec 2018 13:43 #
I was referring to XQuery update writeback, chop option is set to false:
$ basex.bat -u -w -c"set exporter omit-xml-declaration=no,indent=no" -itest.xml update.xqueryupdate.xquery:
for $c in doc(document-uri())//kennung
return
(replace value of node $c with "REPLACED")test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<root><vs>
<kennung>test</kennung>
<absatz> <fett>eins</fett>
</absatz>
</vs>
</root>Result
<?xml version="1.0" encoding="UTF-8"?>
<root><vs><kennung>REPLACED</kennung><absatz><fett>eins</fett></absatz><absatz>Test<fett>fett</fett><kursiv>kursiv</kursiv>Text z.B. am 01.02.2018 Text.</absatz></vs></root>Saxon does not change indentation (with declare option saxon:output "indent=no")
Quoted text · Christian Grün · 84 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Donnerstag, 13. Dezember 2018 12:41 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > > The only thing is I prefer the Saxon default about not changing anything on > already existing indentation (BaseX is deleting any indentation with indent=no), > but I am aware this is implementation-defined. > > Existing identation is actually preserved by both BaseX and Saxon: > > declare namespace output = 'http://www.w3.org/2010/xslt-xquery-serialization'; > declare option output:indent 'no'; > parse-xml('<a> > <b/> > </a>') > > Were you referring to documents with chopped whitespaces? > > Cheers > Christian > > > > > > -----Ursprüngliche Nachricht----- > > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > > Gesendet: Mittwoch, 12. Dezember 2018 18:47 > > > An: Zimmel, Daniel > > > Cc: BaseX > > > Betreff: Re: [basex-talk] Command line options not working with update > operation > > > on input file > > > > > > …I think I got what you were trying to achieve! There is a separate > > > option for exporting databases and writing updates. This may be more > > > obvious now after another updates of our documentation [1]. > > > > > > Here is a little self-contained BaseX call that (as I hope) > > > demonstrates the behavior: > > > > > > basex -u -c"set exporter omit-xml-declaration=no" > > > "file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" > > > "fetch:xml('doc.xml')" > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > <a> > > > <b/> > > > </a> > > > > > > You can also run the following command script ("basex script.bxs"): > > > > > > set exporter omit-xml-declaration=no > > > set writeback on > > > xquery file:write('doc.xml', <a/>) > > > xquery insert node <a/> into doc('doc.xml')/* > > > xquery fetch:xml('doc.xml') > > > > > > Maybe we’ll merge these two options in a future release of BaseX. > > > Until then, just add an EXPORTER option to your .basex file with the > > > identical serialization parameters. > > > > > > Best > > > Christian > > > > > > [1] http://docs.basex.org/wiki/Options#WRITEBACK > > > > > > > > > > > > > > > On Wed, Dec 12, 2018 at 6:35 PM Christian Grün > > > <christian.gruen at gmail.com> wrote: > > > > > > > > > Any serialization parameter gets ignored from the command line with > XQuery > > > Update. > > > > > > > > > > Has this been solved? Is this a bug? > > > > > > > > XML declarations are never stored in the database. Instead, they will > > > > be added during serialization. So I’m not exactly on what you just > > > > tried to do. Could you please give some step-by-step instructions?
CG
Christian Grün13 Dec 2018 13:48 #
This is what I get:
<?xml version="1.0" encoding="UTF-8"?>
<root><vs>
<kennung>REPLACED</kennung>
<absatz> <fett>eins</fett>
</absatz>
</vs>
</root>Do you possibly have some settings in your .basex configuration file that I should consider? Or do you have a 'test' database with chopped whitespaces that is opened instead of your test.xml document?
Quoted text · Daniel · 115 lines
On Thu, Dec 13, 2018 at 1:43 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> wrote: > > I was referring to XQuery update writeback, chop option is set to false: > > $ basex.bat -u -w -c"set exporter omit-xml-declaration=no,indent=no" -itest.xml update.xquery > > update.xquery: > > for $c in doc(document-uri())//kennung > return > (replace value of node $c with "REPLACED") > > test.xml: > > <?xml version="1.0" encoding="UTF-8"?> > <root><vs> > <kennung>test</kennung> > <absatz> <fett>eins</fett> > </absatz> > </vs> > </root> > > > Result > > <?xml version="1.0" encoding="UTF-8"?> > <root><vs><kennung>REPLACED</kennung><absatz><fett>eins</fett></absatz><absatz>Test<fett>fett</fett><kursiv>kursiv</kursiv>Text z.B. am 01.02.2018 Text.</absatz></vs></root> > > > Saxon does not change indentation (with declare option saxon:output "indent=no") > > > -----Ursprüngliche Nachricht----- > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > Gesendet: Donnerstag, 13. Dezember 2018 12:41 > > An: Zimmel, Daniel > > Cc: BaseX > > Betreff: Re: [basex-talk] Command line options not working with update operation > > on input file > > > > > The only thing is I prefer the Saxon default about not changing anything on > > already existing indentation (BaseX is deleting any indentation with indent=no), > > but I am aware this is implementation-defined. > > > > Existing identation is actually preserved by both BaseX and Saxon: > > > > declare namespace output = 'http://www.w3.org/2010/xslt-xquery-serialization'; > > declare option output:indent 'no'; > > parse-xml('<a> > > <b/> > > </a>') > > > > Were you referring to documents with chopped whitespaces? > > > > Cheers > > Christian > > > > > > > > > > -----Ursprüngliche Nachricht----- > > > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > > > Gesendet: Mittwoch, 12. Dezember 2018 18:47 > > > > An: Zimmel, Daniel > > > > Cc: BaseX > > > > Betreff: Re: [basex-talk] Command line options not working with update > > operation > > > > on input file > > > > > > > > …I think I got what you were trying to achieve! There is a separate > > > > option for exporting databases and writing updates. This may be more > > > > obvious now after another updates of our documentation [1]. > > > > > > > > Here is a little self-contained BaseX call that (as I hope) > > > > demonstrates the behavior: > > > > > > > > basex -u -c"set exporter omit-xml-declaration=no" > > > > "file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" > > > > "fetch:xml('doc.xml')" > > > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > > <a> > > > > <b/> > > > > </a> > > > > > > > > You can also run the following command script ("basex script.bxs"): > > > > > > > > set exporter omit-xml-declaration=no > > > > set writeback on > > > > xquery file:write('doc.xml', <a/>) > > > > xquery insert node <a/> into doc('doc.xml')/* > > > > xquery fetch:xml('doc.xml') > > > > > > > > Maybe we’ll merge these two options in a future release of BaseX. > > > > Until then, just add an EXPORTER option to your .basex file with the > > > > identical serialization parameters. > > > > > > > > Best > > > > Christian > > > > > > > > [1] http://docs.basex.org/wiki/Options#WRITEBACK > > > > > > > > > > > > > > > > > > > > On Wed, Dec 12, 2018 at 6:35 PM Christian Grün > > > > <christian.gruen at gmail.com> wrote: > > > > > > > > > > > Any serialization parameter gets ignored from the command line with > > XQuery > > > > Update. > > > > > > > > > > > > Has this been solved? Is this a bug? > > > > > > > > > > XML declarations are never stored in the database. Instead, they will > > > > > be added during serialization. So I’m not exactly on what you just > > > > > tried to do. Could you please give some step-by-step instructions?
ZD
Zimmel, Daniel13 Dec 2018 14:18 #
Thanks for the hint. Yes, in my .basex there is a CHOP=false; when I delete it, it works as expected.
But as I pointed out, this looks like a bug to me:
With the same query, when CHOP=false in the .basex file and -w switch on the command line, whitespace gets chopped (not expected!)
Input
<root><vs>
<kennung>TTT</kennung>
<absatz><fett>eins</fett> und <fett>zwei</fett>
</absatz>
</vs>
</root>.basex:
CHOP=false
Result
<?xml version="1.0" encoding="UTF-8"?>
<root><vs><kennung>TTT</kennung><absatz><fett>eins</fett>und<fett>zwei</fett></absatz></vs></root>Quoted text · Christian Grün · 148 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Donnerstag, 13. Dezember 2018 13:49 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > This is what I get: > > <?xml version="1.0" encoding="UTF-8"?> > <root><vs> > <kennung>REPLACED</kennung> > <absatz> <fett>eins</fett> > </absatz> > </vs> > </root> > > Do you possibly have some settings in your .basex configuration file > that I should consider? Or do you have a 'test' database with chopped > whitespaces that is opened instead of your test.xml document? > > > > On Thu, Dec 13, 2018 at 1:43 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> > wrote: > > > > I was referring to XQuery update writeback, chop option is set to false: > > > > $ basex.bat -u -w -c"set exporter omit-xml-declaration=no,indent=no" -itest.xml > update.xquery > > > > update.xquery: > > > > for $c in doc(document-uri())//kennung > > return > > (replace value of node $c with "REPLACED") > > > > test.xml: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <root><vs> > > <kennung>test</kennung> > > <absatz> <fett>eins</fett> > > </absatz> > > </vs> > > </root> > > > > > > Result > > > > <?xml version="1.0" encoding="UTF-8"?> > > > <root><vs><kennung>REPLACED</kennung><absatz><fett>eins</fett></absatz > ><absatz>Test<fett>fett</fett><kursiv>kursiv</kursiv>Text z.B. am 01.02.2018 > Text.</absatz></vs></root> > > > > > > Saxon does not change indentation (with declare option saxon:output > "indent=no") > > > > > -----Ursprüngliche Nachricht----- > > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > > Gesendet: Donnerstag, 13. Dezember 2018 12:41 > > > An: Zimmel, Daniel > > > Cc: BaseX > > > Betreff: Re: [basex-talk] Command line options not working with update > operation > > > on input file > > > > > > > The only thing is I prefer the Saxon default about not changing anything on > > > already existing indentation (BaseX is deleting any indentation with > indent=no), > > > but I am aware this is implementation-defined. > > > > > > Existing identation is actually preserved by both BaseX and Saxon: > > > > > > declare namespace output = 'http://www.w3.org/2010/xslt-xquery- > serialization'; > > > declare option output:indent 'no'; > > > parse-xml('<a> > > > <b/> > > > </a>') > > > > > > Were you referring to documents with chopped whitespaces? > > > > > > Cheers > > > Christian > > > > > > > > > > > > > > -----Ursprüngliche Nachricht----- > > > > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > > > > Gesendet: Mittwoch, 12. Dezember 2018 18:47 > > > > > An: Zimmel, Daniel > > > > > Cc: BaseX > > > > > Betreff: Re: [basex-talk] Command line options not working with update > > > operation > > > > > on input file > > > > > > > > > > …I think I got what you were trying to achieve! There is a separate > > > > > option for exporting databases and writing updates. This may be more > > > > > obvious now after another updates of our documentation [1]. > > > > > > > > > > Here is a little self-contained BaseX call that (as I hope) > > > > > demonstrates the behavior: > > > > > > > > > > basex -u -c"set exporter omit-xml-declaration=no" > > > > > "file:write('doc.xml', <a/>)" "insert node <b/> into doc('doc.xml')/*" > > > > > "fetch:xml('doc.xml')" > > > > > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > > > <a> > > > > > <b/> > > > > > </a> > > > > > > > > > > You can also run the following command script ("basex script.bxs"): > > > > > > > > > > set exporter omit-xml-declaration=no > > > > > set writeback on > > > > > xquery file:write('doc.xml', <a/>) > > > > > xquery insert node <a/> into doc('doc.xml')/* > > > > > xquery fetch:xml('doc.xml') > > > > > > > > > > Maybe we’ll merge these two options in a future release of BaseX. > > > > > Until then, just add an EXPORTER option to your .basex file with the > > > > > identical serialization parameters. > > > > > > > > > > Best > > > > > Christian > > > > > > > > > > [1] http://docs.basex.org/wiki/Options#WRITEBACK > > > > > > > > > > > > > > > > > > > > > > > > > On Wed, Dec 12, 2018 at 6:35 PM Christian Grün > > > > > <christian.gruen at gmail.com> wrote: > > > > > > > > > > > > > Any serialization parameter gets ignored from the command line with > > > XQuery > > > > > Update. > > > > > > > > > > > > > > Has this been solved? Is this a bug? > > > > > > > > > > > > XML declarations are never stored in the database. Instead, they will > > > > > > be added during serialization. So I’m not exactly on what you just > > > > > > tried to do. Could you please give some step-by-step instructions?
CG
Christian Grün13 Dec 2018 14:25 #
Quoted text · Zimmel, Daniel · 1 line
> With the same query, when CHOP=false in the .basex file and -w switch on the command line, whitespace gets chopped (not expected!)
The option is toggled (see one of my previous replies). We should revise the help text on the command-line in a future version.
ZD
Zimmel, Daniel13 Dec 2018 14:32 #
Looks like I was not getting the toggle part correctly.
Yes it is very confusing since it says:
"-w Preserve whitespaces from input files"
Thanks! I will toggle this now in my internal documentation :-)
Quoted text · Christian Grün · 13 lines
> -----Ursprüngliche Nachricht----- > Von: Christian Grün [mailto:christian.gruen at gmail.com] > Gesendet: Donnerstag, 13. Dezember 2018 14:26 > An: Zimmel, Daniel > Cc: BaseX > Betreff: Re: [basex-talk] Command line options not working with update operation > on input file > > > With the same query, when CHOP=false in the .basex file and -w switch on the > command line, whitespace gets chopped (not expected!) > > The option is toggled (see one of my previous replies). We should > revise the help text on the command-line in a future version.
CG
Christian Grün13 Dec 2018 16:03 #
True, the documentation of the command-line flags hasn’t been updated for quite a while now. I’ve just caught up on that. BaseX 9.1.1 is scheduled for tomorrow, it will include the updated help texts.
Quoted text · Daniel · 22 lines
On Thu, Dec 13, 2018 at 2:32 PM Zimmel, Daniel <D.Zimmel at esvmedien.de> wrote: > > Looks like I was not getting the toggle part correctly. > Yes it is very confusing since it says: > > "-w Preserve whitespaces from input files" > > Thanks! I will toggle this now in my internal documentation :-) > > > -----Ursprüngliche Nachricht----- > > Von: Christian Grün [mailto:christian.gruen at gmail.com] > > Gesendet: Donnerstag, 13. Dezember 2018 14:26 > > An: Zimmel, Daniel > > Cc: BaseX > > Betreff: Re: [basex-talk] Command line options not working with update operation > > on input file > > > > > With the same query, when CHOP=false in the .basex file and -w switch on the > > command line, whitespace gets chopped (not expected!) > > > > The option is toggled (see one of my previous replies). We should > > revise the help text on the command-line in a future version.
Written for BaseX 9.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery