1) +1 to "it should make no difference"
No conforming XML processor should produce different results with or without
CDATA sections.
2) +1 to "how did you evaluate the query"
If your expecting QConsole or any other method that *parses* the result it wont
see the CDATA (see #2)
TO validate this you can make a REST endpoint or use any number of popular
tools to get at 'the raw data'
For many tools nowadays its actually quite tedious to NOT have it parse the
results of xml and strip the CDATA
Likewise its also hard to have them NOT re-encode the data before you see it
(with CDATA or more often XML character escapes -
Example: I use xmlsh (www.xmlsh.org) and the marklogic extension which under
the hood uses XCC and has an option to produce the 'raw' data as text (-t) or
force XML parsing (no -t)
It can be tedious to follow the entire chain of processing involved in all the
layers of tooling -- many give no options for what they do. This can lead to
confusion.
Hopefully this is less confusing :)
You can validate the same thing by making a simple HTTP endpoint running a
XQuery and use curl directly
to avoid intermediate libraries mucking with things.
The following demonstrates the correct behavior
( in xmlsh )
import ml=marklogic
export MLCONNECT=xcc://user:pass@localhost:8000
### Text output - no parsing of output Note treatment of strings as well as
CDATA
MLCONNECT=xcc://admin:admin@localhost:8000
import ml=marklogic
ml:query -t 'declare option xdmp:output "cdata-section-elements=myElement" ;
<root><myElement>text</myElement>{"<fakexml/>"}</root>'
--- Produces
<root><myElement><![CDATA[text]]></myElement><fakexml/></root>
### Parse XML output then serialize
### the parser (xerces) strips out the CDATA as it is required to but still
encodes the reserved XML chars.
MLCONNECT=xcc://admin:admin@localhost:8000
import ml=marklogic
ml:query 'declare option xdmp:output "cdata-section-elements=myElement" ;
<root><myElement>text</myElement>{"<fakexml/>"}</root>'
--- Produces
<root>
<myElement>text</myElement><fakexml/></root>
--- Now JUST a string
ml:query '"<fakexml/>"'
--->
<fakexml/>
vs ---
-----
ml:query -t '"<fakexml/>"'
--->
<fakexml/>
-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell: +1 812-630-7622
www.marklogic.com
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Florent Georges
Sent: Tuesday, October 20, 2015 10:10 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] cdata-section-elements option doesn't
produce CDATA-values
On 20 October 2015 at 15:45, Schouten, Edgar J. (RB-NL) wrote:
Hi,
> This application requires <![CDATA[-fields
Which means it is not expecting XML. CDATA is syntactic sugar.
Whether it is used or not, equivalent XML documents should be treated the same
(regardless of CDATA sections). Not everything has to be XML, so it might be
OK, but often "issues" with CDATA are an application configured the wrong way
and rejecting well-formed XML when it should not.
> declare option xdmp:output "cdata-section-elements=myElement";
This can be applied only if the serializer gets into play. How are you
evaluating the query, and how are you saving (or displaying) its result?
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general