Hello again,

Just to follow up on my original inquiry, I am trying to use the cdata-section-elements serialization parameter to write an XHTML XForms document (now to the filesystem rather than a database).

The BaseX documentation indicates that the file:write function can take a $params argument with serialization parameters, and it and gives cdata-section-elements as an example. However, I haven't been successful in my attempt to use this.

Here is a Gist that illustrates my basic use case: https://gist.github.com/Timathom/486b1fcf05d2c69ec176

I submit to a RESTXQ endpoint from an XForms document, then write another XForms doc to the filesystem, placing the results of a SPARQL query in the <script> element.

When I open the resulting "turtle-test.xhtml" file, the <script> element still lacks a CDATA section and the angle brackets have been escaped.

Thanks again for your help!

Tim

--
Tim A. Thompson
Metadata Librarian (Spanish/Portuguese Specialty)
Princeton University Library


On Fri, Jul 10, 2015 at 9:24 AM, Tim Thompson <timathom@gmail.com> wrote:
Excellent! Thank you for fixing this so quickly.

Tim

--
Tim A. Thompson
Metadata Librarian (Spanish/Portuguese Specialty)
Princeton University Library


On Fri, Jul 10, 2015 at 9:16 AM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Tim,

The default element namespace declaration will now be considered when
parsing the cdata-section-elements option. I have just uploaded a new
snapshot [1], and 8.2.3 will available soon.

Thanks to your feedback, two more bugs in the W3 XQuery 3.1 Test Suite
could be fixed. In includes around 28.000 tests, and we are currently
covering around 99%.

Thanks,
Christian

[1] http://files.basex.org/releases/latest/



On Fri, Jul 10, 2015 at 2:08 PM, Christian Grün
<christian.gruen@gmail.com> wrote:
> Hi Tim,
>
> Thanks for the example code. It noticed that BaseX fails to recognize
> CDATA section elements if a default element namespace is set:
>
>   declare default element namespace "http://www.w3.org/1999/xhtml";
>   declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
>   declare option output:cdata-section-elements "xml";
>   <xml><![CDATA[ < ]]></xml>
>
> The following query works (but it's quite obviously not what you need):
>
>   declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
>   declare option output:cdata-section-elements "xml";
>   <xml><![CDATA[ < ]]></xml>
>
> I will check the serialization spec again and fix this as soon as possible.
> Christian
>
>
> On Fri, Jul 10, 2015 at 1:40 PM, Tim Thompson <timathom@gmail.com> wrote:
>> Dirk,
>>
>> Thanks for your reply. Here's a simple example. When I run this query with
>> Saxon HE 9.6, the output contains a CDATA section, but when I run it in the
>> BaseX GUI, there is no CDATA and the angle brackets are escaped. Has this
>> serialization parameter been implemented in BaseX?
>>
>> xquery version "3.0";
>>
>> declare copy-namespaces no-preserve, no-inherit;
>> declare default element namespace "http://www.w3.org/1999/xhtml";
>> declare namespace output =
>> "http://www.w3.org/2010/xslt-xquery-serialization";
>> declare option output:method "xhtml";
>> declare option output:indent "yes";
>> declare option output:encoding "utf-8";
>> declare option output:cdata-section-elements "script";
>>
>> let $turtle :=
>> <turtle>
>>     <![CDATA[
>>     @prefix ex: <http://example.org/> .
>>     @prefix test: <http://test.org/> .
>>
>>     ex:test1 a test:Test .
>>     ]]>
>> </turtle>
>>
>> let $html :=
>> <html>
>>     <head>
>>         <meta
>>             content="text/html; charset=UTF-8"
>>             http-equiv="Content-Type"/>
>>         <title>Turtle Test</title>
>>     </head>
>>     <body>
>>         <h1>Turtle Test</h1>
>>         <script
>>             type="text/turtle">{
>>             $turtle/text()
>>         }</script>
>>     </body>
>> </html>
>>
>> return
>>     $html
>>
>>
>> Saxon output:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <html
>>     xmlns="http://www.w3.org/1999/xhtml">
>>     <head>
>>         <meta
>>             content="text/html; charset=utf-8"
>>             http-equiv="Content-Type" />
>>         <title>Turtle Test</title>
>>     </head>
>>     <body>
>>         <h1>Turtle Test</h1>
>>         <script type="text/turtle"><![CDATA[
>>
>>     @prefix ex: <http://example.org/> .
>>     @prefix test: <http://test.org/> .
>>
>>     ex:test1 a test:Test .
>>
>> ]]></script>
>>     </body>
>> </html>
>>
>>
>> BaseX output:
>>
>> <html
>>   xmlns="http://www.w3.org/1999/xhtml">
>>   <head>
>>     <meta
>>       content="text/html; charset=UTF-8"
>>       http-equiv="Content-Type" />
>>     <title>Turtle Test</title>
>>   </head>
>>   <body>
>>     <h1>Turtle Test</h1>
>>     <script type="text/turtle">
>>
>>     @prefix ex: &lt;http://example.org/&gt; .
>>     @prefix test: &lt;http://test.org/&gt; .
>>
>>     ex:test1 a test:Test .
>>
>> </script>
>>   </body>
>> </html>
>>
>>
>>
>> --
>> Tim A. Thompson
>> Metadata Librarian (Spanish/Portuguese Specialty)
>> Princeton University Library
>>
>>
>> On Fri, Jul 10, 2015 at 4:39 AM, Dirk Kirsten <dk@basex.org> wrote:
>>>
>>> Hello Tim,
>>>
>>> CDATA is just ordinary (encoded) text to XQuery, i.e. there is no
>>> special CDATA data type. Therefore, instead of saving the document in
>>> this way you should adapt the output accordingly. So when you serialize
>>> your output you can use the map {"cdata-section-elements": "script"} to
>>> output the result as CDATA section. You can read a bit more about this
>>> in our documentation at http://docs.basex.org/wiki/Serialization
>>>
>>> Cheers
>>> Dirk
>>>
>>> On 07/09/2015 08:31 PM, Tim Thompson wrote:
>>> > Hello,
>>> >
>>> > I am trying to retrieve some non-XML RDF data (as "text/turtle") from
>>> > a SPARQL endpoint. I need to output the Turtle as a CDATA section
>>> > inside a <script> tag in an XForms (X)HTML file, then add that file to
>>> > a database.
>>> >
>>> > The file gets added correctly, but I'm not able to generate the CDATA
>>> > section. Here is the function:
>>> >
>>> > db:add("xforms", document {
>>> >         $xslt-pi,
>>> >         $css,
>>> >         $form
>>> > }, "turtle-test.xml", map {"cdata-section-elements": "script"})
>>> >
>>> > When I run this, I get an error: [bxerr:BASX0002] Unknown database
>>> > option 'cdata-section-elements'.
>>> >
>>> > I get the same error no matter which option I use (not just
>>> > "cdata-section-elements"), so I guess I may be using the wrong syntax.
>>> >
>>> > Hope someone can point me in the right direction!
>>> >
>>> > Thanks in advance,
>>> > Tim
>>> >
>>> > --
>>> > Tim A. Thompson
>>> > Metadata Librarian (Spanish/Portuguese Specialty)
>>> > Princeton University Library
>>> >
>>>
>>> --
>>> Dirk Kirsten, BaseX GmbH, http://basexgmbh.de
>>> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
>>> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
>>> |   Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle
>>> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
>>>
>>