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:Utils.java

public static Element findElementElseCreateAndSetAndAttribute(Document document, Element parent, String element,
        String value, String attributeName, String attributeValue) {

    Element e = findElementElseCreateAndAttribute(document, parent, element, attributeName, attributeValue);
    if (e != null)
        e.appendChild(document.createTextNode(value));

    return e;//from   w  w  w  .  ja  v a  2s  . co  m
}

From source file:Main.java

public static Element createElement(Document document, String name, String value) {
    if (value != null) {
        Element element = (Element) document.createElement(name);
        element.appendChild(document.createTextNode(value));
        return element;
    }//w  ww .  j ava 2  s .  c o m
    throw new IllegalArgumentException(
            "XMLDocumentUtils.createElement: value of " + name + " element can't be null.");
}

From source file:Utils.java

public static Element findContainerWithAttributeValueElseCreateAndSet(Document document, Element parent,
        String element, String value, String attributeName, String attributeValue) {

    Element e = findContainerWithAttributeValueElseCreate(document, parent, element, attributeName,
            attributeValue);// w w  w  .j a v a 2s.c  o  m
    e.appendChild(document.createTextNode(value));

    return e;
}

From source file:Main.java

public static void addChildElement(Element element, String child_ele_name, String text) {
    Document doc = element.getOwnerDocument();
    Element sub_element = createLeafElement(doc, child_ele_name, text);
    element.appendChild(sub_element);
}

From source file:Main.java

/**
 * Adds an element to another of a document in memory <br>
 * (It's supposed that the parent is one element of the document)
 * //from   w  w w.  ja v  a2 s.c  o m
 * @param doc
 *            Document of the parent element
 * @param parent
 *            Parent element where a child element will be added
 * @param elementName
 *            The name of the child element
 * 
 * @return org.w3c.dom.Element
 */
public static Element addElementChildToElement(Document doc, Element parent, String elementName) {
    // Creates the element and adds it to the parent
    Element element = doc.createElement(elementName);
    parent.appendChild(element);

    return element;
}

From source file:Main.java

public static void addParameter(Document outDoc, Element succFail, String name, String value) {
    //System.out.println("value:" + value);
    Element parameters = (Element) succFail.getElementsByTagName("parameters").item(0);
    Element parameter = outDoc.createElement(name);
    parameter.setAttribute("value", value);
    parameters.appendChild(parameter);
}

From source file:Main.java

public static void nodeSubUpdate(Element root, String table, String queryType, String queryValue) {
    Node find = getTag(root, table);
    Document doc = find.getOwnerDocument();

    NodeList nl = find.getChildNodes();
    int numnodes = nl.getLength();

    System.out.println("length : " + numnodes);

    Node replNode = null;//from  w w w .  j  a  v  a 2s . c  o m

    for (int i = 0; i < numnodes; i++) {
        Node n = nl.item(i);
        String name = n.getNodeName();

        if (name.equals(queryType)) {
            replNode = n;
            System.out.println("Finding Node : " + replNode.getNodeName());

            break;
        }
    }

    Element type = doc.createElement(queryType);
    Text value = doc.createTextNode(queryValue);

    type.appendChild(value);

    find.replaceChild(type, replNode);

    print(doc);
}

From source file:Utils.java

/**
 * Add a new element to the given parent
 * @param parent the parent Element//from   ww  w.j  a v  a 2  s  .  c om
 * @param name the child name
 * @return new Element
 */
public static Element createElement(Element parent, String name) {
    Document document;
    Element element;

    document = parent.getOwnerDocument();
    element = document.createElement(name);

    parent.appendChild(element);
    return element;
}

From source file:Main.java

/**
 * Creates a DOM element node with the given name and contents. If indicated
 * the contents is enclosed in CDATA marks.
 * //ww w  .j  ava 2 s  .  com
 * @param d
 *            the "mother" document of the created Element
 * @param name
 *            the name of the element
 * @param value
 *            the element's value
 * @param isCDATA
 *            a flag indicating if this element contains (unformatted)
 *            CDATA.
 * @return a new DOM Element
 */
public static Element createElement(Document d, String name, String value, boolean isCDATA) {
    Element e = createElement(d, name);
    if (isCDATA)
        e.appendChild(createCDATA(d, value));
    else
        e.appendChild(createText(d, value));
    return e;
}

From source file:Main.java

public static Element createElement(Document document, String nsURI, String name, String value) {
    if (value != null) {
        Element element = (Element) document.createElementNS(nsURI, name);
        element.appendChild(document.createTextNode(value != null ? value : ""));
        return element;
    }//from w  w  w. j av  a 2s . co  m
    throw new IllegalArgumentException(
            "XMLDocumentUtils.createElement: value of " + name + " element can't be null.");
}