This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes JAXB: Creating a message with a CDATA section Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB: Creating a message with a CDATA section" Watch "JAXB: Creating a message with a CDATA section" New topic
Author

JAXB: Creating a message with a CDATA section

Rick Portugal
Ranch Hand

Joined: Dec 17, 2002
Posts: 243
How can I use JAXB to create an XML message that contains a CDATA tag?
I want to create an XML message that looks like this:

<thisTag><![CDATA[
123 456
789 321 ]]></thisTag>

But I can't figure out how to get "CDATA" to appear in the message.


IBM 286, SCJP, SCWCD, EIEIO
Rick Portugal
Ranch Hand

Joined: Dec 17, 2002
Posts: 243
I tried to force the CDATA tag by prepending the string "<!CDATA[[" to the contents of my data. But JAXB translated it to "& l t ; !CDATA[[". Does anybody know how to tell JAXB not to convert "<" to "& l t ;"?
[ December 29, 2004: Message edited by: Rick Portugal ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 13001
    
    5
The org.w3c.dom.Document class has a method:
createCDATASection( String contents )
I'm not sure where JAXB fits into this, but Java 1.4 includes that package as part of the normal library.
Bill
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: JAXB: Creating a message with a CDATA section
 
jQuery in Action, 3rd edition