List of usage examples for org.w3c.dom Document createElement
public Element createElement(String tagName) throws DOMException;
From source file:Main.java
/** * * @param doc Document/*w w w .ja v a 2 s . c om*/ * @param parent Node * @param name String * @param value int * @return Element */ public static Element appendChildNodeCDATA(Document doc, Node parent, String name, int value) { Element child = doc.createElement(name); child.appendChild(doc.createCDATASection(new Integer(value).toString())); parent.appendChild(child); return child; }
From source file:Main.java
private static Element constructDocument() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); Element rootElement = doc.createElement("root"); doc.appendChild(rootElement);/* w w w. j av a2 s .c om*/ Element c1Element = doc.createElement("c1"); Element c2Element = doc.createElement("c2"); Element c3Element = doc.createElement("c3"); Element gc1Element = doc.createElement("gc1_1"); Element gc2Element = doc.createElement("gc1_2"); Text textNode = doc.createTextNode("uncle_freddie"); Element gc3Element = doc.createElement("gc2_1"); rootElement.appendChild(c1Element); rootElement.appendChild(c2Element); rootElement.appendChild(c3Element); c1Element.appendChild(gc1Element); c1Element.appendChild(gc2Element); c2Element.appendChild(gc3Element); gc3Element.appendChild(textNode); return rootElement; }
From source file:Main.java
/** * Add a child element with the given text contents to the specified element. * //from w w w .ja v a2 s . co m * @param doc Document object, used to build new elements. * @param elem Element to append new child to. * @param childName Name of the new child element. * @param childText Text contents of the new child element. */ public static void addChildText(Document doc, Element elem, String childName, String childText) { Element newChild = doc.createElement(childName); newChild.setTextContent(childText); elem.appendChild(newChild); }
From source file:Main.java
/** * Create an element with the specified name * * @param parent//from w w w.ja va2 s. co m * @param tagName * @return */ public static Element createElement(Element parent, String tagName) { Document doc = parent.getOwnerDocument(); Element child = doc.createElement(tagName); parent.appendChild(child); return child; }
From source file:Main.java
/** * create an child element with the specified name and value and append it in a parent element * * @param parent/*from w w w . j a v a2s . c o m*/ * @param tagName * @param value * @return */ public static Element createElement(Element parent, String tagName, String value) { Document doc = parent.getOwnerDocument(); Element child = doc.createElement(tagName); setElementValue(child, value); parent.appendChild(child); return child; }
From source file:Main.java
public static Element addDocumentElement(Document doc, String nodeName) { Element el = null;//w w w .ja va 2s . c om if (doc != null) { el = doc.createElement(nodeName); doc.appendChild(el); } return el; }
From source file:Main.java
public static Element createCDATAElement(String name, Object value, Document doc) { Element element = doc.createElement(name); element.appendChild(doc.createCDATASection(value.toString())); return element; }
From source file:Main.java
/** * * @param doc Document/* ww w .j a v a2 s . c om*/ * @param parent Node * @param name String * @param value String * @return Element */ public static Element appendChildNodeCDATA(Document doc, Node parent, String name, String value) { Element child = doc.createElement(name); child.appendChild(doc.createCDATASection(value)); parent.appendChild(child); return child; }
From source file:Main.java
/** * This is used to create a child node/*from www . ja va2 s. c o m*/ * * @param document * @param parent * @param childName * @param childContents */ public static void addChildElement(Document document, Element parent, String childName, String childContents) { Element childElement = document.createElement(childName); childElement.setTextContent(childContents); parent.appendChild(childElement); }
From source file:Main.java
public static Element addElement(Document document, Element parentElement, String elementName) { Element childElement = document.createElement(elementName); parentElement.appendChild(childElement); return childElement; }