Example usage for org.w3c.dom Node appendChild

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

Introduction

In this page you can find the example usage for org.w3c.dom Node 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

/**
 * Adds all Nodes of the source NodeList to the destination Node
 * /* ww w  . j  a  v  a 2  s. co  m*/
 * @param dst the destination NodeList
 * @param src the source Node
 **/
public final static void addAll(final Node dst, final NodeList src) {
    final int size = size(src);

    for (int i = 0; i < size; i++) {
        dst.appendChild(src.item(i));
    }
}

From source file:Main.java

/**
 * Adds a simple DOM Node like <tagName>text</tagName> to a given node in a document
 *
 * @param XMLDocument current XML document
 * @param rootElement element you want append the new node to
 * @param tagName node's tag name//w w w .j  a v a2  s  .  c om
 * @param text text in the node
 */
public static void addTextNode(Document XMLDocument, Node rootElement, String tagName, String text) {
    Element newNode = XMLDocument.createElement(tagName);
    newNode.appendChild(XMLDocument.createTextNode(text));
    rootElement.appendChild(newNode);
}

From source file:Main.java

public static void addChildValue(Document doc, Node parent, String childName, String childValue) {
    Element element = doc.createElement(childName);
    Text text = doc.createTextNode(childValue);
    element.appendChild(text);/*  www.j a va 2 s  .  com*/
    parent.appendChild(element);
}

From source file:Main.java

public static void addTextTag(Node node, String tagName, String text) {
    Document doc = node.getOwnerDocument();
    Element elem = doc.createElement(tagName);
    elem.appendChild(doc.createTextNode(text));
    node.appendChild(elem);
}

From source file:Main.java

/**
   Set the text of a specified node. A text section is added to
   the node if necessary./* w w  w  .  j  a v  a 2s. c  o  m*/
 */
static public void setText(Node node, String value) {
    if (node == null)
        return;

    Node child = findChild(node, "#text");
    if (child == null)
        node.appendChild(node.getOwnerDocument().createTextNode(value));
    else
        child.setNodeValue(value);
}

From source file:Main.java

/**
 *
 * @param doc Document/*w  w w.  j  a 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

/**
 * Creates and returns a new XML node with the specified name, as a child
 * of the given parent/*w w w. j a v a 2  s .  c om*/
 * Returns null if the child could not be created
 */
public static Node createChild(Node parent, String name) {
    // Create the node
    Node child = parent.getOwnerDocument().createElement(name);
    if (child != null) {
        // Add it to the document
        parent.appendChild(child);
    }

    return child;
}

From source file:Main.java

public static void appendChild(Node parent, Node... nodes) {
    Document doc = parent.getOwnerDocument();
    for (Node node : nodes) {
        if (node.getOwnerDocument() != doc) {
            parent.appendChild(doc.importNode(node, true));
        } else {//from   w w w  . java2s  .  c o m
            parent.appendChild(node);
        }
    }
}

From source file:Main.java

public static Element createNewElement(Node elem, String tag) {// throws Exception {
    if (elem instanceof Document) {
        Document doc = (Document) elem;
        Element res = doc.createElement(tag);
        elem.appendChild(res);
        return res;
    } else {//  w w w  .  j  ava 2  s.  com
        Document doc = elem.getOwnerDocument();
        Element res = doc.createElement(tag);
        elem.appendChild(res);
        return res;
    }
}

From source file:Main.java

public static void addNode(Document doc, Node parent, String ns, String name, String text, Map NS_MAP) {
    Element child = doc.createElementNS((String) NS_MAP.get(ns), ns + ":" + name);
    child.appendChild(doc.createTextNode(text));
    parent.appendChild(child);
}