[jdom-interest] Replace existing CDATA

Jason Long jason at supernovasoftware.com
Sat Feb 16 14:10:27 PST 2002

Sorry my mistake.  The actual XML is as follows:

<name num="1"><![CDATA[Bob Marley & The Wailers - Legend - 02 - No Woman No

The code does work since there is no whitespace.

Best Regards,

Jason Long - President
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 Elliotte Rusty Harold
Sent: Saturday, February 16, 2002 3:45 PM
To: Jason Long; JDOM
Subject: Re: [jdom-interest] Replace existing CDATA

At 12:23 AM -0600 2/16/02, Jason Long wrote:
>I have an Element name as follows:
>   <name num="1">
>     <![CDATA[Bob Marley & The Wailers - Legend - 02 - No Woman No
>   </name>
>I am using the following code to remove the CDATA and replace it with a
>processed version of itself.
>   eltName.removeContent((CDATA) eltName.getContent().get(0));
>   eltName.addContent(new CDATA(fileName));
>Is there a cleaner or better way to accomplish this?

Just looking at it I don't think that code would work. It seems to me
that it would throw a ClasscastException. eltName.getContent().get(0)
would not return the CDATA section node. It would return the first
text node which contains only white space.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|              http://www.ibiblio.org/xml/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |
To control your jdom-interest membership:

More information about the jdom-interest mailing list