Parsing options on db:add (cdata-section-elements)

Thursday, 9 July 2015 · 9 messages · last reply 13 Jul 2015
TT
Tim Thompson9 Jul 2015 22:32 #
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
DK
Dirk Kirsten10 Jul 2015 10:39 #
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
Quoted text · Tim Thompson · 33 lines
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
CG
Christian Grünin reply to Tim Thompson, 10 Jul 2015, 15:4110 Jul 2015 14:08 #
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
Quoted text · Tim Thompson · 162 lines
On Fri, Jul 10, 2015 at 1:40 PM, Tim Thompson <timathom at 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 at 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 >> >
CG
Christian Grün10 Jul 2015 15:16 #
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/
Quoted text · Christian Grün · 184 lines
On Fri, Jul 10, 2015 at 2:08 PM, Christian Grün <christian.gruen at 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 at 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 at 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 >>> >>
TT
Tim Thompsonin reply to Dirk Kirsten, 10 Jul 2015, 10:3910 Jul 2015 15:41 #
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
Quoted text · Dirk Kirsten · 55 lines
On Fri, Jul 10, 2015 at 4:39 AM, Dirk Kirsten <dk at 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 > >
TT
Tim Thompsonin reply to Christian Grün, 10 Jul 2015, 15:1610 Jul 2015 17:25 #
Excellent! Thank you for fixing this so quickly. Tim
-- Tim A. Thompson Metadata Librarian (Spanish/Portuguese Specialty) Princeton University Library <tat2 at princeton.edu>
Quoted text · Christian Grün · 213 lines
On Fri, Jul 10, 2015 at 9:16 AM, Christian Grün <christian.gruen at 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 at 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 at 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 at 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 > >>> > >> >
TT
Tim Thompson10 Jul 2015 20:58 #
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
Quoted text · Tim Thompson · 231 lines
On Fri, Jul 10, 2015 at 9:24 AM, Tim Thompson <timathom at gmail.com> wrote: > Excellent! Thank you for fixing this so quickly. > > Tim > > -- > Tim A. Thompson > Metadata Librarian (Spanish/Portuguese Specialty) > Princeton University Library > <tat2 at princeton.edu> > > On Fri, Jul 10, 2015 at 9:16 AM, Christian Grün <christian.gruen at 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 at 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 at 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 at 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 >> >>> >> >> >> > >
CG
Christian Grün13 Jul 2015 10:40 #
Hi Tim, I must confess I haven't run your full example, but you'll probably need to explicitly specify the namespace of your script element, as shown in the following two function calls:
  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script> &lt; </script>
    </xml>,
    <output:serialization-parameters>
      <output:method
        value="xhtml"/>
      <output:cdata-section-elements
        value="Q{{http://www.w3.org/1999/xhtml}}script"/>
    </output:serialization-parameters>
  )

  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script> &lt; </script>
    </xml>,
    map {
      'cdata-section-elements':
      'Q{http://www.w3.org/1999/xhtml}script'
    }
  )
Otherwise, the CDATA section does only apply to the empty namespace:
  file:write("result.xml",
    <xml xmlns="http://www.w3.org/1999/xhtml">
      <script xmlns=""> &lt; </script>
    </xml>,
    map { 'cdata-section-elements': 'script' }
  )
Regarding your second question: (: Does this work? :) %output:cdata-section-elements("script") Yes, that's indeed a valid way to specify serialization parameters. Hope this helps, Christian
TT
Tim Thompson13 Jul 2015 20:15 #
Thank you, that works perfectly! I also found a workaround using "html" as the output method, which lets me create a CDATA section with syntax-specific comments, for example:
<script type="text/turtle">{concat('#<![CDATA[', $body, '#]]>')}</script>
(Following the W3C example for embedding Turtle in XHTML[1].) Best regards, Tim [1] http://www.w3.org/TR/turtle/#xhtml
-- Tim A. Thompson Metadata Librarian (Spanish/Portuguese Specialty) Princeton University Library
Quoted text · Christian Grün · 49 lines
On Mon, Jul 13, 2015 at 4:40 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Tim, > > I must confess I haven't run your full example, but you'll probably > need to explicitly specify the namespace of your script element, as > shown in the following two function calls: > > file:write("result.xml", > <xml xmlns="http://www.w3.org/1999/xhtml"> > <script> &lt; </script> > </xml>, > <output:serialization-parameters> > <output:method > value="xhtml"/> > <output:cdata-section-elements > value="Q{{http://www.w3.org/1999/xhtml}}script"/> > </output:serialization-parameters> > ) > > file:write("result.xml", > <xml xmlns="http://www.w3.org/1999/xhtml"> > <script> &lt; </script> > </xml>, > map { > 'cdata-section-elements': > 'Q{http://www.w3.org/1999/xhtml}script' > } > ) > > Otherwise, the CDATA section does only apply to the empty namespace: > > file:write("result.xml", > <xml xmlns="http://www.w3.org/1999/xhtml"> > <script xmlns=""> &lt; </script> > </xml>, > map { 'cdata-section-elements': 'script' } > ) > > Regarding your second question: > > (: Does this work? :) > %output:cdata-section-elements("script") > > Yes, that's indeed a valid way to specify serialization parameters. > > Hope this helps, > Christian >

⚡Generated with XQuery