List of usage examples for org.w3c.dom Document createTextNode
public Text createTextNode(String data);
Text
node given the specified string. From source file:Main.java
public static Element createLeafElement(Document doc, String eleName, String text) { Element ele = doc.createElement(eleName); if (text != null) { ele.appendChild(doc.createTextNode(text)); }// w w w. j av a2s .c o m return ele; }
From source file:Main.java
public static Element createTextElement(Document dom, String tagName, String content) { Element root = dom.createElement(tagName); if (content != null) root.appendChild(dom.createTextNode(content)); return root;/*from www. j a v a 2 s .c o m*/ }
From source file:Main.java
public static void addValuedElement(Document document, Element parent, String elementName, String content) { Element name = document.createElement(elementName); Text text = document.createTextNode(content); name.appendChild(text);//w w w .jav a 2s . com parent.appendChild(name); }
From source file:Main.java
/** * Creates a DOM text element/*from www . j a v a 2 s. com*/ * @param parent parent DOM element * @param tagName element name * @param text element text * @return a DOM element */ public static Element createTextElement2(Element parent, String tagName, String text) { Document doc = parent.getOwnerDocument(); Element e = doc.createElement(tagName); e.appendChild(doc.createTextNode(text)); parent.appendChild(e); return e; }
From source file:Main.java
/** * Create a property element. Do not append it though! * @param doc The document to use.//from w w w . j a v a2 s .co m * @param name The name of the property. * @param value The value to add to the property. * @return The newly created property. */ public static Node createProperty(final Document doc, final String name, final String value) { final Node n = doc.createElement(name); n.appendChild(doc.createTextNode(value)); return n; }
From source file:Main.java
/** * create an element from a document, that has some text content in it * @param doc - document/*from w w w. j a va 2 s . c o m*/ * @param name - element name * @param content - text content * @return element object */ public static Element createElement(Document doc, String name, String content) { Element e = doc.createElement(name); e.appendChild(doc.createTextNode(content)); return e; }
From source file:Main.java
public static Node cloneNode(Document d, Node n) { Node r = null;//from w ww .j ava2 s.co m switch (n.getNodeType()) { case Node.TEXT_NODE: r = d.createTextNode(((Text) n).getData()); break; case Node.CDATA_SECTION_NODE: r = d.createCDATASection(((CDATASection) n).getData()); break; case Node.ELEMENT_NODE: r = d.createElement(((Element) n).getTagName()); NamedNodeMap map = n.getAttributes(); for (int i = 0; i < map.getLength(); i++) { ((Element) r).setAttribute(((Attr) map.item(i)).getName(), ((Attr) map.item(i)).getValue()); } break; } return r; }
From source file:Main.java
public static Element writeBooleanElement(Document document, String name, boolean value, Element parentElement) {/* w w w. j a v a 2 s. c o m*/ Element element = document.createElement(name); Text text = document.createTextNode(Boolean.toString(value)); element.appendChild(text); parentElement.appendChild(element); return element; }
From source file:Main.java
public static Element addTextNode(Document xmlDoc, Element ndParent, String nodeName, String nodeValue) { Element ndNode = xmlDoc.createElement(nodeName); Text ndTextNode = xmlDoc.createTextNode(nodeName); ndTextNode.setData(nodeValue);/*www. java 2 s . co m*/ ndNode.appendChild(ndTextNode); ndParent.appendChild(ndNode); return ndNode; }
From source file:Main.java
/** * Creates a child element with the given name and appends it to the element child node list. Also * creates a Text node with the given value and appends it to the new elements child node list. *//*from www . j a v a 2 s . co m*/ public static Element addChildElementValue(Element element, String childElementName, String childElementValue, Document document) { Element newElement = addChildElement(element, childElementName, document); newElement.appendChild(document.createTextNode(childElementValue)); return newElement; }