Java DOM edit: Replacing a Text Node with a New CDATASection Node
public void addCDATA(Document doc) { Element root = doc.getDocumentElement(); Element place = (Element)root.getFirstChild(); Element directions = (Element)place.getLastChild(); String dirtext = ">>>\n" + "<<<\n" + "&&&\n" + "<><><>."; CDATASection dirdata = doc.createCDATASection(dirtext); directions.replaceChild(dirdata,directions.getFirstChild()); }