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

Jason Hunter jhunter at xquery.com
Fri Feb 27 15:01:09 PST 2004


The code should still work.  CDATA extends Text which extends Content, 
and there's an addContent(Content).

-jh-

Jason Long wrote:

> 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
> operation.  
> 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")) {
>                 out.write("<text>");
>                 out.write("<![CDATA[");
>                 outputElementContent(element, out);
>                 out.write("]]>");
>                 out.write("</text>");
>             }
>             else {
>                 super.printElement(element, out, level, stack);
>             }
>         }
>     }
> 
> Brad
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
> rhost.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 



More information about the jdom-interest mailing list