Search code examples
xmlxquerycdatamarklogic

MarkLogic 5 return elements wrapped in CDATA


I'm trying to get MarkLogic5 to return items wrapped in a CDATA tag but it simply refuses to. Doesn't barf, just doesn't do it. Am I barking up the wrong tree using: -

xquery version "1.0-ml";

declare option xdmp:output "cdata-section-elements = text";

<text><![CDATA[\begin{eqnarray}
 \fl {R}_{\mathrm{sw}(e)}=\nonumber\\ \fl \biggl \{ \frac{3{L}_{1}{L}_{2}{Q}_{\mathrm{after}}}{1 2{k}_{h}{A}_{h}\Delta T({L}_{1}+{L}_{2})-({L}_{1}+{L}_{2})^{2}({Q}_{\mathrm{before}}-{Q}_{\mathrm{after}})}-1\biggr \} \nonumber\\ \times ~\frac{{L}_{1}{L}_{2}}{({L}_{1}+{L}_{2}){k}_{h}{A}_{h}}-{R}_{j}-{R}_{\mathrm{CNT}},
            \end{eqnarray} ]]>
</text>

Simply returns without the CDATA tag which is contrary to all documentation I can find. I've tried returning the content several ways, e.g., xdmp:quote but as I need to parse the content using XSLT at the other end it really needs to be wrapped in a CDATA element.

The content is normally deeply nested but I've simplified here for ease.

Any clues?

Update

As per the answers from Ron and David it was actually adding the CDATA, it was only my various IDEs, including qconsole and eclipse, hiding it from me for convenience.

That said, the reason I was trying to ensure those elements were wrapped in CDATA is because it's part of a larger XML document embedded within another and JAXB was choking on this particular content as well as custom processing instructions such as <?THING content ?>. This was just an attempt to fool JAXB into treating it purely as a String.


Solution

  • As Mike suggested, it appears to be the rendering in the browser with QC that is causing the CDATA to disappear. I changed the sample XQuery to this:

    xquery version "1.0-ml";
    
    declare option xdmp:output "cdata-section-elements = text";
    
    xdmp:save ("/tmp/testfoo.xml", 
    <text><![CDATA[\begin{eqnarray}
     \fl {R}_{\mathrm{sw}(e)}=\nonumber\\ \fl \biggl \{ \frac{3{L}_{1}{L}_{2}{Q}_{\mathrm{after}}}{1 2{k}_{h}{A}_{h}\Delta T({L}_{1}+{L}_{2})-({L}_{1}+{L}_{2})^{2}({Q}_{\mathrm{before}}-{Q}_{\mathrm{after}})}-1\biggr \} \nonumber\\ \times ~\frac{{L}_{1}{L}_{2}}{({L}_{1}+{L}_{2}){k}_{h}{A}_{h}}-{R}_{j}-{R}_{\mathrm{CNT}},
            \end{eqnarray} ]]>
    </text>
    )
    

    Looking at the file on disk, it looks like this:

    <text><![CDATA[\begin{eqnarray}^
     \fl {R}_{\mathrm{sw}(e)}=\nonumber\\ \fl \biggl \{ \frac{3{L}_{1}{L}_{2}{Q}_{\mathrm{after}}}{1 2{k}_{h}{A}_{h}\Delta T({L}_{1}+{L}_{2})-({L}_{1}+{L}_{2})^{2}({Q}_{\mathrm{before}}-{Q}_{\mathrm{after}})}-1\biggr \} \nonumber\\ \times ~\frac{{L}_{1}{L}_{2}}{({L}_{1}+{L}_{2}){k}_{h}{A}_{h}}-{R}_{j}-{R}_{\mathrm{CNT}},^M
            \end{eqnarray}
    ]]></text>
    

    When QC handles the XML resulting from your query, the CDATA is eliminated because it's never kept internally by MarkLogic. So it's no longer there when QC serializes its output to your browser.