Example usage for org.w3c.dom Element appendChild

List of usage examples for org.w3c.dom Element appendChild

Introduction

In this page you can find the example usage for org.w3c.dom Element appendChild.

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:Main.java

public static void createElementAndAppend(String name, int value, Document doc, Element appendeeElement,
        String attributeName, String attributeValue) {
    Element newElement = doc.createElement(name);
    Text text = doc.createTextNode(String.valueOf(value));
    newElement.appendChild(text);
    if (attributeName != null && !attributeName.equals("")) {
        newElement.setAttribute(attributeName, attributeValue);
    }/*from  w ww. j a va  2  s  . com*/
    appendeeElement.appendChild(newElement);
}

From source file:Main.java

public static void createElementAndAppend(String name, double value, Document doc, Element appendeeElement,
        String attributeName, String attributeValue) {
    Element newElement = doc.createElement(name);
    Text text = doc.createTextNode(String.valueOf(value));
    newElement.appendChild(text);
    if (attributeName != null && !attributeName.equals("")) {
        newElement.setAttribute(attributeName, attributeValue);
    }/*from www  .j ava 2  s.  c o m*/
    appendeeElement.appendChild(newElement);
}

From source file:Main.java

/**
 * Add a child element with the given text contents to the specified element.
 * //w ww  .jav  a2  s  . c  om
 * @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

/**
 * Creates a new element/*from  w  ww  .  j  av  a  2 s .  c  om*/
 * 
 * @param doc
 * @param tag
 * @param data
 * @return
 */
public static Element createElement(Document doc, String tag, String data) {
    Element receiverEmail = doc.createElement(tag);
    if (data != null) {
        Text receiverEmailText = doc.createTextNode(data);
        receiverEmail.appendChild(receiverEmailText);
    }
    return receiverEmail;
}

From source file:Main.java

public static Element createElement(Element parent, String name) {
    Document document;//from w ww.j a va 2  s. c o  m
    Element element;

    document = parent.getOwnerDocument();
    element = document.createElement(name);

    parent.appendChild(element);
    return element;
}

From source file:Main.java

public static void appendChilds(Element element, Vector<Element> childElements) {
    if (element != null && childElements != null) {
        for (Element childElement : childElements) {
            element.appendChild(childElement);
        }//from  w  w  w. j  a  v  a  2s  .c om
    }
}

From source file:Main.java

public static Element addElement(Document doc, Element parent, String nodeName) {
    Element el = null;//from  w w w.  j a va 2 s  .  co m
    if (doc != null)
        el = doc.createElement(nodeName);

    if (parent != null)
        parent.appendChild(el);

    return el;
}

From source file:Main.java

public static Element writeStringElement(Document document, String name, String value, Element parentElement) {
    Element element = document.createElement(name);
    if (value == null) {
        value = "null";
    }/*from  ww  w .  j a v a  2 s  . c o m*/
    Text text = document.createTextNode(value);
    element.appendChild(text);
    parentElement.appendChild(element);
    return element;
}

From source file:Main.java

public static Element createElement(Document document, String name, Element child) {
    Element element = (Element) document.createElement(name);
    element.appendChild(child);
    return element;
}

From source file:Main.java

public static Element createElement(Document document, String nsURI, String name, Element child) {
    Element element = (Element) document.createElement(name);
    element.appendChild(child);
    return element;
}