users@jaxb.java.net

AW: marshalling CDATA data

From: Nick Pellow <nick.pellow_at_mindmatics.de>
Date: Fri, 13 Feb 2004 16:53:33 +0100

well, I have found a solution using apache xerces:
it is not very nice, but it seems to work ok.

1) marshal your object using JAXB to an XML document (not to an output
stream).
2) create an OutputFormat (special class from apache)
3) set the appropriate attributes on the format - of.setCDataElements(new
String[]{"CDATA_ELEMENT_1","CDATA_ELEMENT_2"});
// must set each element that is to be output as a CDATA explicitly...
4) serialise the document to a string using an XMLSerializer passing the
OutputFormat


                Document doc = DOMToolBox.newDocumentBuilder().newDocument();
            marshaller.marshal(toMarshal, doc);

                final OutputFormat of = new OutputFormat();
                of.setPreserveSpace(true);
                of.setCDataElements(new String[]{"CDATA_ELEMENT"});
                of.setIndenting(true);

            final XMLSerializer ser = new XMLSerializer(of);
            final StringWriter writer = new StringWriter();
            ser.setOutputCharStream(writer);
            ser.serialize(doc);
            String xmlString = writer.getBuffer().toString();


I hope this helps!

Cheers,
nick



-----Ursprüngliche Nachricht-----
Von: Lagomasino, Adolfo (Adolfo) [mailto:adolfo_at_lucent.com]
Gesendet: Freitag, 13. Februar 2004 16:38
An: 'users_at_jaxb.dev.java.net'
Betreff: RE: marshalling CDATA data


This is the link to previous discussions.
http://forum.java.sun.com/thread.jsp?forum=34&thread=360343
I've been tracking it and tried several things unsuccessfully also.

Adolfo


-----Original Message-----
From: Nick Pellow [mailto:nick.pellow_at_mindmatics.de]
Sent: Friday, February 13, 2004 3:34 AM
To: users_at_jaxb.dev.java.net
Subject: marshalling CDATA data


Hi,

I think this has been discused before, however just wanting to know the
current best means of doing
the following:

When marshalling to an XML document, I want the contents of a certain
element
to be inside a CDATA block: <![CDATA[ Here!! && ]].


Cheers,
Nick


-----Ursprungliche Nachricht-----
Von: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Gesendet: Freitag, 13. Februar 2004 00:56
An: users_at_jaxb.dev.java.net
Betreff: Re: How to resolve class/interface conflict



> Thanks. I resolve my problem already.

Did I predict the problem correctly? If so, we'd like to know (so that we
can improve the error message, etc)


> On a related question, could you please tell me where I can find what can
I
> set in the
> <jxb:bindings> inside my binding file (e.g. what are the attributes it can
> support, and what can I set to)?

I think you have to look at the spec.

    http://java.sun.com/xml/downloads/jaxb.html

regards,
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net