users@jaxb.java.net

Re: How do I get the CDATA data ?

From: Robert Lowe <rmlowe_at_rmlowe.com>
Date: Tue, 01 Apr 2003 22:33:26 +0800

I guess you would get and set CDATA just like any other text, i.e. using
Strings. I'm not aware of any way to force a CDATA section on marshalling
though.

Since you are using mixed content, the List returned by getContent can
contain any combination of Strings (for raw text) and javax.xml.bind.Element
instances (for child elements). For your example I would expect that the
list would contain a single String corresponding to the CDATA section.

The setContent() method is not necessary because you can call getContent()
and modify the list that it returns. For example:

myScript.getContent().clear();
myScript.getContent().addAll(myList);

would be equivalent to myScript.setContent(myList).


----- Original Message -----
From: "J. Medina" <jmedina_at_ON.COM>
To: <JAXB-INTEREST_at_JAVA.SUN.COM>
Sent: Tuesday, April 01, 2003 10:03 PM
Subject: How do I get the CDATA data ?


> I need to process documents -read and generate- that include CDATA. How do
I get and set this data using the classes generated by JAXB ? Do I need to
include any special bindings ?
>
> Using the schema definitions below, I get a method :
>
> java.util.List getContent();
>
> for the interface ScriptType. What does it return ? a list of what ?
>
> Also, there is nothing like setContent().
>
> Any help is appreciated.
>
>
> <xsd:complexType name="ScriptsType">
> <xsd:sequence>
> <xsd:element name="script"
> minOccurs="0" maxOccurs="unbounded"
> type="ScriptType"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="ScriptType">
> <xsd:complexContent mixed="true">
> <xsd:restriction base="xsd:anyType">
> <xsd:attribute name="name" type="xsd:string"/>
> </xsd:restriction>
> </xsd:complexContent>
> </xsd:complexType>
>
> Here is a small sample:
>
> <script name="install">
> <![CDATA[
> REM Seems that using a CDATA section would be safer in case
> REM some lines contain xml-like lines
> REM <like> <this> <line>
> command < somecommand > othercommand
> ]]>
> </script>