Java examples for XML:DOM
Adding a Text Node to a DOM Document
import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; public class Main { public static void main(String[] args) throws Exception { Document doc = null;/* ww w . j a v a2 s. com*/ // Add a CDATA section to the root element Element element = doc.getDocumentElement(); Text text = doc.createTextNode("data\n"); element.appendChild(text); // Special characters are automatically converted to entities by the XML // writers text = doc.createTextNode("<>&\"'"); element.appendChild(text); } }