[jdom-interest] Replace existing CDATA
Elliotte Rusty Harold
elharo at metalab.unc.edu
Sat Feb 16 13:45:18 PST 2002
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 Cry.mp3]]>
> </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/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list