[jdom-interest] Element.addContent(CDATA cdata) depreciation suggestion?

Jason Long jason at supernovasoftware.com
Fri Feb 27 14:43:44 PST 2004

Thank you for the suggestion.
The following is currently doing exactly what I am looking for:

elt3.addContent((new CDATA(((new XMLOutputter()).outputString(elt2)))));

I would like to avoid creating another class just to do this one
My problem is that Element.addContent(CDATA cdata) is depreciated.  I
looked in the javadoc for beta8 and beta9, but I could no note of its
depreciation in beta8 and it is not present in the src of beta9.  Could
someone please offer a simple solution to this depreciated method?

Jason Long - CEO and Chief Software Engineer
Supernova Software - supernovasoftware.com
BS Physics, MS Chemical Engineering  

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]
On Behalf Of Bradley S. Huffman
Sent: Friday, February 27, 2004 9:31 AM
To: Jason Long
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] (no subject)

"Jason Long" writes:

> I am not sure I follow.
> My code is as follows:
> Element elt0 = new Element("story");
> Element elt1 = (Element) xpath.selectSingleNode(docJDOM);
> elt0.addContent(elt1.clone());
> This is currently serialized as:
> <story>
>   <text>
>        Test test test <br/>
>        Test test test <br/>
>        Test test test <br/>
>   </text>
> </story>
> I need it to be as follows:
> </story>
>   <text><![CDATA[
>        Test test test <br/>
>        Test test test <br/>
>        Test test test <br/>
>         ]]>
>   </text>
> </story>

How about this, extend XMLOutputter and override printElement

    public class MyOutputter extends XMLOutputter {

        protected void printElement(Element element, Writer out,
                                    int level, NamespaceStack stack) {
            if ((element.getName()).equals("text")) {
                outputElementContent(element, out);
            else {
                super.printElement(element, out, level, stack);

To control your jdom-interest membership:

More information about the jdom-interest mailing list