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 Element createChild(Document doc, Element root, String name) {
    Element elem = doc.createElement(name);
    root.appendChild(elem);
    return elem;/* www  .  ja va 2 s. c  o  m*/
}

From source file:Main.java

/**
 *
 * @param doc Document//w  ww .  ja v a 2s .co  m
 * @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

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

From source file:Main.java

public static Element createTextElement(Document dom, String tagName, String content) {
    Element root = dom.createElement(tagName);
    if (content != null)
        root.appendChild(dom.createTextNode(content));
    return root;/*from   w  ww.  j  a va  2s .c  o m*/
}

From source file:Main.java

public static void createChildTextWithComment(Document paramDocument, Element paramElement, String paramString1,
        String paramString2, String paramString3) {
    Element localElement = paramDocument.createElement(paramString1);
    localElement.appendChild(paramDocument.createTextNode((paramString2 == null) ? "" : paramString2));
    Comment localComment = paramDocument.createComment(paramString3);
    paramElement.appendChild(localComment);
    paramElement.appendChild(localElement);
}

From source file:Main.java

public static Element createLeafElement(Document doc, String eleName, String text) {
    Element ele = doc.createElement(eleName);
    if (text != null) {
        ele.appendChild(doc.createTextNode(text));
    }//from   w  w  w. j  a v  a2  s  . co  m
    return ele;
}

From source file:Main.java

public static Element createSimpleTextElementWithoutNS(final Document documentParent,
        final String elementTagName, final String elementText) {
    Element element = documentParent.createElement(elementTagName);
    element.appendChild(documentParent.createTextNode(elementText));
    return element;
}

From source file:Main.java

public static void createComment(Document doc, Element elem, String comment) {
    Comment c = doc.createComment(comment);
    elem.appendChild(c);
}

From source file:Main.java

/**
 * Appends the child element as well as value to the parent element.
 *
 * @param parent the parent element//from w  ww  .  j a  va 2  s .  co m
 * @param tagName the child element name
 * @param value the child element value
 * @return the child element added to the parent element
 */
public static Element appendElement(Element parent, String tagName, String value) {
    Element child = appendElement(parent, tagName);
    child.appendChild(child.getOwnerDocument().createTextNode(value));
    return child;
}

From source file:Main.java

/**
 * add a comment below element el/*from w ww.  j a  v a2s.  c  om*/
 */
public static void addComment(Document outDoc, Element el, String cText) {
    Comment com = outDoc.createComment(cText);
    el.appendChild(com);
}