Java examples for XML:CDATA
Adding a CDATA Section to a DOM Document
import org.w3c.dom.CDATASection; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static void m() { // Obtain an XML document; this method is implemented in Document doc = null;/*w ww. j a v a 2s . co m*/ // Add a CDATA section to the root element Element element = doc.getDocumentElement(); CDATASection cdata = doc.createCDATASection("data"); element.appendChild(cdata); // If "]]>" appears in the text, two CDATA sections will be written out cdata = doc.createCDATASection("more]]>data"); element.appendChild(cdata); } }