1 18 19 package org.apache.tools.ant.util; 20 21 import org.w3c.dom.CDATASection ; 22 import org.w3c.dom.Document ; 23 import org.w3c.dom.Element ; 24 import org.w3c.dom.Text ; 25 26 28 36 public class DOMUtils { 37 38 43 public static Document newDocument() { 44 return JAXPUtils.getDocumentBuilder().newDocument(); 45 } 46 47 67 public static Element createChildElement(Element parent, String name) { 68 Document doc = parent.getOwnerDocument(); 69 Element e = doc.createElement(name); 70 parent.appendChild(e); 71 return e; 72 } 73 74 90 public static void appendText(Element parent, String content) { 91 Document doc = parent.getOwnerDocument(); 92 Text t = doc.createTextNode(content); 93 parent.appendChild(t); 94 } 95 96 112 public static void appendCDATA(Element parent, String content) { 113 Document doc = parent.getOwnerDocument(); 114 CDATASection c = doc.createCDATASection(content); 115 parent.appendChild(c); 116 } 117 118 137 public static void appendTextElement(Element parent, String name, 138 String content) { 139 Element e = createChildElement(parent, name); 140 appendText(e, content); 141 } 142 143 163 public static void appendCDATAElement(Element parent, String name, 164 String content) { 165 Element e = createChildElement(parent, name); 166 appendCDATA(e, content); 167 } 168 } 169 | Popular Tags |