users@jaxb.java.net

Re: CDATA in marshalling output?

From: Robert Lowe <rmlowe_at_RMLOWE.COM>
Date: Thu, 03 Apr 2003 20:42:57 +0800

I'm curious about why you need to output CDATA.

My understanding is that a CDATA section is always equivalent to a normal
text section with certain characters escaped. So, for example, this:

<response>
    <data>
        <![CDATA[
            some strange text < < <
        ]]>
    </data>
</response>

is exactly equivalent to this:

<response>
    <data>
            some strange text &lt; &lt; &lt;
    </data>
</response>

I guess the thinking in JAXB is that there is no need to use CDATA; you just
output literal text (without CDATA sections and without escapes), and JAXB
will take care of inserting the necessary escapes. In other words, if you
just use data.setValue("some strange text < < <") (or
data.getContent().add("some strange text < < <"), depending on the content
model), JAXB will marshal the content as in the second example above.


----- Original Message -----
From: "Walter Klust" <walter.klust_at_IMATRIS.DE>
To: <JAXB-INTEREST_at_JAVA.SUN.COM>
Sent: Thursday, April 03, 2003 6:14 PM
Subject: CDATA in marshalling output?


> I need to build XML-Output which contains CDATA-sections. E.g.:
>
> <response>
> <data>
> <![CDATA[
> some strange text < < <
> ]]>
> </data>
> </response>
>
>
> My problem is that i dont know how to tell the marshaller to stop escaping
certain characters.
> So far the output i am able to produce looks like this:
>
> <response>
> <data>
> &lt;![CDATA[
> some strange text &lt; &lt; &lt;
> ]]&gt;
> </data>
> </response>
>
>
> Can you help me with hints or tips how to solve this problem?
>
> regards
>
> walter