List of usage examples for org.w3c.dom Element appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:Main.java
public static void createElementAndAppend(String name, String value, Document doc, Element appendeeElement, String attributeName, String attributeValue) { if (value == null || value.equals("")) { log.info("XMLUtil.createElementAndAppend() value == null for name = " + name + "."); value = ""; }//from w w w . j av a2 s . c o m Element newElement = doc.createElement(name); Text text = doc.createTextNode(value); newElement.appendChild(text); if (attributeName != null && !attributeName.equals("")) { newElement.setAttribute(attributeName, attributeValue); } appendeeElement.appendChild(newElement); }
From source file:Main.java
public static Element createTextElement(Element parent, String tagName, String text) { Document doc = parent.getOwnerDocument(); Element e = createElement(parent, tagName); if (text == null) { text = ""; }//w w w . j a v a 2 s. c o m e.appendChild(doc.createTextNode(text)); return e; }
From source file:Main.java
public static Element newElement(Element elParent, String tagName, String text) { Element element = newElement(elParent, tagName); if (null != element) { Text tx = element.getOwnerDocument().createTextNode(text); element.appendChild(tx); }/*from w w w . j a v a 2 s.c o m*/ return element; }
From source file:Main.java
static public void textContentTag(Element parent, String tagName, String content) { Element tag = parent.getOwnerDocument().createElement(tagName); tag.setTextContent(content);//from w w w .j a v a2s . co m parent.appendChild(tag); }
From source file:Main.java
public static Element appendChildElement(Element parentNode, String nodeName) { Document doc = parentNode.getOwnerDocument(); Element childNode = doc.createElement(nodeName); parentNode.appendChild(childNode); return childNode; }
From source file:Main.java
/** * Creates a child element with the given name and appends it to the element child node list. *//* ww w .j av a 2 s. com*/ public static Element addChildElement(Element element, String childElementName, Document document) { Element newElement = document.createElement(childElementName); element.appendChild(newElement); return newElement; }
From source file:Main.java
private static void insertNode(String nodeName, String nodeValue) { File f = new File(System.getProperty("user.dir") + "\\DBConf.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;/*from ww w . j a va 2 s.c o m*/ try { builder = factory.newDocumentBuilder(); Document doc = builder.parse(f); Element tempElem = doc.createElement(nodeName); Text child = doc.createTextNode(nodeValue); tempElem.appendChild(child); doc.getElementsByTagName("conf").item(0).appendChild(tempElem); DOMSource source = new DOMSource(doc); StreamResult Streamres = new StreamResult(new FileOutputStream(f)); TransformerFactory.newInstance().newTransformer().transform(source, Streamres); } catch (Exception e) { e.printStackTrace(); } }
From source file:Utils.java
public static Element createNewElementAndSet(Document document, Element parent, String childElement, String childValue) {//from w w w . jav a2s .c om Element child = (Element) document.createElement(childElement); parent.appendChild(child); child.setNodeValue(childValue); child.appendChild(document.createTextNode(childValue)); return child; }
From source file:Main.java
public static Node addChildNode(Node pNode, String name, String value) { Document _doc = null;//from w ww .j av a 2 s . co m if (pNode.getNodeType() == Node.DOCUMENT_NODE) { _doc = (Document) pNode; } else { _doc = pNode.getOwnerDocument(); } Element _ele = _doc.createElement(name); Node _node = _doc.createTextNode(value); _ele.appendChild(_node); return pNode.appendChild(_ele); }
From source file:Main.java
public static void addSimpleOutput(Element success, Document outDoc, String tagName, String value) { Element output = (Element) success.getElementsByTagName("output").item(0); Element outItem = outDoc.createElement(tagName); outItem.setTextContent(value);//from w ww . j ava 2 s . co m output.appendChild(outItem); }