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

/**
 * Creates the element./*  w  w w. j a  v  a  2s  .co  m*/
 *
 * @param parent
 *          the parent
 * @param nodeName
 *          the node name
 *
 * @return the element
 */
public static Element createElement(final Node parent, final String nodeName) {
    final Element child = parent.getOwnerDocument().createElement(nodeName);
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static void setTextContent(Node node, String nodeValue) {

    if (node == null || nodeValue == null)
        throw new NullPointerException();

    node.appendChild(node.getOwnerDocument().createTextNode(xmlEncode(nodeValue)));
}

From source file:Main.java

/**
 *
 * @param doc Document/*from   w w w. j ava 2  s .c om*/
 * @param parent Node
 * @param name String
 * @return Element
 */
public static Element appendChildNode(Document doc, Node parent, String name) {
    Element child = doc.createElement(name);
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static void addNode(Document doc, Node parent, String name, String text) {
    Element child = doc.createElement(name);
    child.appendChild(doc.createTextNode(text));
    parent.appendChild(child);
}

From source file:Main.java

public static void addNewElementWithAttribute(Document xmlDoc, Node node, String elementName,
        String elementValue, String attrName, String attrValue) {
    // element//ww  w  . j a  v a2 s.  c  o m
    Node newVal = xmlDoc.createElement(elementName);
    Node newValText = xmlDoc.createTextNode(elementValue);
    newVal.appendChild(newValText);
    // attribute
    addAttribute(xmlDoc, newVal, attrName, attrValue);
    // add to node
    node.appendChild(newVal);
}

From source file:Main.java

public static Node addNode(Document doc, Node parent, String name) {
    Node child = null;//from   w ww.ja v  a2 s.  co m
    try {
        child = doc.createElement(name);
        return parent.appendChild(child);
    } catch (DOMException ex) {
        try {
            if (child != null)
                parent.removeChild(child);
        } catch (DOMException ex2) {
        }
        return null;
    }
}

From source file:Main.java

/**
 * Create a new element in the parent node with the given local name and namespace.
 * @param parent The node to which the new element will be appended.
 * @param namespace The namespace of the new element to be created
 * @param name The local name of the new element to be created
 * @return The newly created element./*from   ww w  .  java2s. c o m*/
 */
public static Element makeElementNS(Node parent, String namespace, String name) {
    Document d = getDoc(parent);
    Element result = d.createElementNS(namespace, name);
    parent.appendChild(result);
    return result;
}

From source file:Main.java

public static void appendChild(Document document, Node root, String name, String value) {
    Node node = document.createElement(name);
    node.appendChild(document.createTextNode(value != null ? value : ""));
    root.appendChild(node);/*  w  w  w .  j  a  v  a 2s  .com*/
    return;
}

From source file:Main.java

public static void addDataText(Document doc, Node parent, String elementName, String elementData) {
    Element e = doc.createElement(elementName);
    e.appendChild(doc.createTextNode(elementData));
    parent.appendChild(e);
}

From source file:Main.java

public static Node addTag(Document doc, Node e, String index, String value) {
    org.w3c.dom.Element tag = doc.createElement(index);
    tag.appendChild(doc.createTextNode(value));
    return e.appendChild(tag);
}