Shouldn't CHOP = false make xml:space="preserve" the default behavior?
Saturday, 5 August 2017 · 1 message
OM
Ottid Mes5 Aug 2017 13:35 #
From the documentation about the CHOP option I assumed that since xml:space="preserve" sets CHOP = false for that part of the document, that if I set CHOP = false in my configuration file, that the behavior you get when you use xml:space="preserve" would be applied to the whole database (I created the database after setting the option). However the only way I have ever been able to get this behavior, has been to set xml:space="preserve" at the root element. Am I missing something, or is this a bug? How could I get this behavior by default in my databases?
I thought this would not warrent a thorough example given the clear conditions which cause the above situation, but I was asked for it anyway, so here it goes:
A little bit of context, although it should not matter, I have had this issue for years (at least 4) under Arch Linux. At the time I just assumed I did something wrong and went with xml:space="preserve" workaround everywhere.
Quoted text · 1 line
> uname -a
Linux phoenix 4.9.38 #1-NixOS SMP Sat Jul 15 10:17:55 UTC 2017 x86_64 GNU/Linux
The default situation:
No config file (.basex)
Quoted text · 1 line
> basex
BaseX 8.6.4 [Standalone]
Quoted text · 1 line
> create db chop-test
Database 'chop-test' created in 123.01 ms.
Quoted text · 1 line
> open chop-test
Database 'chop-test' was opened in 1.19 ms.
Quoted text · 1 line
> replace /a <root><a><b>foo</b></a> bar</root>
0 resource(s) replaced in 103.68 ms.
Quoted text · 1 line
> xquery /root
<root>
<a>
<b>foo</b>
</a>bar</root>
Query executed in 106.05 ms.I never use the REPL other than to create and drop databases, so I was a bit suprised that this did not work:
Quoted text · 1 line
> replace /a <root xml:space="preserve"><a><b>foo</b></a> bar</root>
"a.xml" (Line 1): Open quote is expected for attribute "xml:space" associated with an element type "root".
While this does:
Quoted text · 1 line
> replace /a <root xml:space='preserve'><a><b>foo</b></a> bar</root>
1 resource(s) replaced in 4.06 ms.
Quoted text · 1 line
> xquery /root
<root xml:space="preserve"><a><b>foo</b></a> bar</root>
Query executed in 0.95 ms.
Quoted text · 1 line
> quit
Have fun.
The resource with xml:space="preserve" is the behavior I want to have within my database, because all my documents are mixed content.
On the wiki (http://docs.basex.org/wiki/Options#CHOP) this is also mentioned:
It explicitly states that in my use case I should set CHOP to false: "The flag should be turned off if a document contains mixed content."
It also states that setting the xml:space="preserve" attribute is the same as having CHOP = false:
"If the xml:space="preserve" attribute is attached to an element, chopping will be turned off for all descendant text nodes."
So lets do that:
Let us first confirm that the config file is correctly read:
Quoted text · 2 lines
> echo 'FOO = 0' > /some/path/.basex > BASEX_JVM='-Dorg.basex.path=/some/path' basex
/some/path/.basex: Unknown option 'FOO'.
/some/path/.basex: writing new configuration file.
Now we set the option CHOP = false in our config:
Quoted text · 1 line
> echo 'CHOP = false' >> /some/path/.basex
So lets see what this changes in the basex REPL:
Quoted text · 1 line
> BASEX_JVM='-Dorg.basex.path=/some/path' basex
BaseX 8.6.4 [Standalone]
Quoted text · 1 line
> drop db chop-test
Database 'chop-test' was dropped.
Quoted text · 1 line
> create db chop-test
Database 'chop-test' created in 106.42 ms.
Quoted text · 1 line
> open chop-test
Database 'chop-test' was opened in 0.05 ms.
Quoted text · 1 line
> replace /a <root><a><b>foo</b></a> bar</root>
0 resource(s) replaced in 39.24 ms.
Quoted text · 1 line
> xquery /root
<root>
<a>
<b>foo</b>
</a> bar</root>
Query executed in 97.09 ms.Quoted text · 1 line
> quit
Have fun.
This is not what I expect, it should have been:
Quoted text · 1 line
> xquery /root
<root><a><b>foo</b></a> bar</root>And hence my question: Shouldn't CHOP = false make xml:space="preserve" the default behavior?
I even tried this:
Quoted text · 1 line
> BASEX_JVM='-Dorg.basex.path=/some/path' basex
BaseX 8.6.4 [Standalone]
Try 'help' to get more information.
Quoted text · 1 line
> open chop-test
Database 'chop-test' was opened in 90.65 ms.
Quoted text · 3 lines
> set chop off CHOP: false > replace /a <root><a><b>foo</b></a> bar</root>
1 resource(s) replaced in 45.58 ms.
Quoted text · 1 line
> xquery /root
<root>
<a>
<b>foo</b>
</a> bar</root>
Query executed in 96.78 ms.Quoted text · 1 line
> quit
See you.
Am I making some mistake in the above?
Is the wiki simply outdated and should this be configured differently? Is having having mixed content in basex so rare that this bug has gone unnoticed for years?
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery