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 Node getMagicNode(Document doc, String content) {
    Element magicNode = doc.createElement("KMagicNode");
    magicNode.appendChild(doc.createCDATASection(content));
    return magicNode;
}

From source file:Main.java

public static void cdataContentTag(Element parent, String tagName, String cdata) {
    Element tag = parent.getOwnerDocument().createElement(tagName);
    tag.appendChild(parent.getOwnerDocument().createCDATASection(cdata));
    parent.appendChild(tag);//from ww  w . java 2s.c o  m
}

From source file:Main.java

public static void edit(Document doc) {

    Element root = doc.createElementNS(null, "person"); // Create Root Element
    Element item = doc.createElementNS(null, "name"); // Create element
    item.appendChild(doc.createTextNode("Jeff"));
    root.appendChild(item); // Attach element to Root element
    item = doc.createElementNS(null, "age"); // Create another Element
    item.appendChild(doc.createTextNode("28"));
    root.appendChild(item); // Attach Element to previous element down tree
    item = doc.createElementNS(null, "height");
    item.appendChild(doc.createTextNode("1.80"));
    root.appendChild(item); // Attach another Element - grandaugther
    doc.appendChild(root); // Add Root to Document
}

From source file:Main.java

public static void createOptionalChildText(Document paramDocument, Element paramElement, String paramString1,
        String paramString2) {//from w w w . j a  v a  2  s  .  co m
    if ((paramString2 == null) || (paramString2.length() == 0))
        return;
    Element localElement = paramDocument.createElement(paramString1);
    localElement.appendChild(paramDocument.createTextNode(paramString2));
    paramElement.appendChild(localElement);
}

From source file:Main.java

public static Element addElement(Document doc, String name, Element parent) {
    Element ee = doc.createElement(name);
    parent.appendChild(ee);
    return ee;//  w  w w  . j a v  a 2 s.c  om
}

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//from   w w  w. j a v  a2s .  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

/**
 * Adds a text node to the provided element.
 * @param nodeName The name of the node.
 * @param doc The XML Document./*w ww . j a v a 2  s.co  m*/
 * @param parent The Element node to attach the text node to.
 * @param text The text to place in the node.
 */
private static void appendTextNode(String nodeName, Document doc, Element parent, String text) {
    if (text != null) {
        Element el = doc.createElement(nodeName);
        el.appendChild(doc.createTextNode(text));
        parent.appendChild(el);
    }
}

From source file:Main.java

public static Element appendElementChild(Document doc, Element parent, String name) {
    Element el = doc.createElement(name);
    parent.appendChild(el);
    return el;//from   ww w. j a v  a 2s  . c om
}

From source file:Main.java

/**
 * internal function for adding an element to the DOM tree.
 *///  w ww. j  av  a 2s .  c o m
private static void addNode(Document doc, String elemName, String value) {
    Element root = doc.getDocumentElement();
    Element elem = doc.createElement(elemName);
    elem.appendChild(doc.createTextNode(value));
    root.appendChild(elem);
}

From source file:Main.java

public static Element createLeaf(Document doc, String name, String value) {
    Element leaf = doc.createElement(name);
    if (value != null)
        leaf.appendChild(doc.createTextNode(value));
    return leaf;/*from   w  ww  .j a  va2 s. com*/
}