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

/**
 * Creates a child element with the given name and appends it to the element child node list. Also
 * creates a Text node with the given value and appends it to the new elements child node list.
 *//*w  w  w .  j av a2  s. co  m*/
public static Element addChildElementValue(Element element, String childElementName, String childElementValue,
        Document document) {
    Element newElement = addChildElement(element, childElementName, document);

    newElement.appendChild(document.createTextNode(childElementValue));
    return newElement;
}

From source file:Main.java

/**
 * Creates a child element with the given name and appends it to the element child node list. Also
 * creates a CDATASection node with the given value and appends it to the new elements child node
 * list./* www.ja  va2s .co m*/
 */
public static Element addChildElementCDATAValue(Element element, String childElementName,
        String childElementValue, Document document) {
    Element newElement = addChildElement(element, childElementName, document);

    newElement.appendChild(document.createCDATASection(childElementValue));
    return newElement;
}

From source file:Main.java

public static void appendTextChild(Element parent, String tagname, String text) {
    if (text == null) {
        text = "";
    }//w ww.  ja  v a  2s .  c  o  m
    Document doc = parent.getOwnerDocument();
    Element childElement = doc.createElement(tagname);
    Text textNode = doc.createTextNode(text);
    childElement.appendChild(textNode);
    parent.appendChild(childElement);
}

From source file:Main.java

public static Element getElementWithText(Document doc, String elementName, String textValue) {
    Element elem_text = doc.createElement(elementName);
    elem_text.appendChild(doc.createTextNode(textValue));

    return elem_text;
}

From source file:Main.java

public static Element createNewTextElement(Node elem, String tag, String value) {// throws Exception {
    Document doc = elem.getOwnerDocument();
    Element res = doc.createElement(tag);
    Text content = doc.createTextNode(value);
    res.appendChild(content);
    elem.appendChild(res);// w w  w.  ja v a2 s .c  om
    return res;
}

From source file:Main.java

static public Element createElement(Element parent, String tagName) {
    Element tag = parent.getOwnerDocument().createElement(tagName);
    parent.appendChild(tag);
    return tag;//from  ww  w  .  j  a va 2  s .  c o  m
}

From source file:Main.java

private static void addOneElement(Document file, String text, String elementName) {
    Element newNode = file.createElement(elementName);
    Text textMsg = file.createTextNode(text);
    newNode.appendChild(textMsg);
    file.getDocumentElement().appendChild(newNode);
    file.getDocumentElement().appendChild(file.createTextNode("\n  "));
}

From source file:Main.java

public static Document addRoot(Document dataDoc, String elementName) {
    Element oldRoot = dataDoc.getDocumentElement();
    Element newRoot = dataDoc.createElement(elementName);
    dataDoc.removeChild(oldRoot);//from   w  w w  . j  av  a 2 s . com
    newRoot.appendChild(oldRoot);
    dataDoc.appendChild(newRoot);
    return dataDoc;
}

From source file:Main.java

public static Element AddChild(Element parent, String nodename) {
    Element childnode = parent.getOwnerDocument().createElement(nodename);
    parent.appendChild(childnode);
    return childnode;
}

From source file:Main.java

public static void addValuedElement(Document document, Element parent, String elementName, String content) {
    Element name = document.createElement(elementName);

    Text text = document.createTextNode(content);
    name.appendChild(text);
    parent.appendChild(name);/*from  w w  w .jav a  2s. c o  m*/
}