Example usage for org.w3c.dom Document createElement

List of usage examples for org.w3c.dom Document createElement

Introduction

In this page you can find the example usage for org.w3c.dom Document createElement.

Prototype

public Element createElement(String tagName) throws DOMException;

Source Link

Document

Creates an element of the type specified.

Usage

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  w w w. j ava2  s.  c om
}

From source file:Main.java

public static Element createNewElement(Node elem, String tag) {// throws Exception {
    if (elem instanceof Document) {
        Document doc = (Document) elem;
        Element res = doc.createElement(tag);
        elem.appendChild(res);/*  w  ww  . j  a  va 2 s .  co m*/
        return res;
    } else {
        Document doc = elem.getOwnerDocument();
        Element res = doc.createElement(tag);
        elem.appendChild(res);
        return res;
    }
}

From source file:Main.java

/**
 * Create a success element, and append the correct command name.
 * /*from   w ww.  j ava  2  s . c om*/
 * @param outDoc
 *            the document for output xml
 * @param commandName
 *            name of the successfully executed command
 * @return a <success><commmand name=$commandname /></success> Element
 */
public static Element createSuccess(Document outDoc, String commandName) {
    Element success = outDoc.createElement("success");
    Element cmd = outDoc.createElement("command");
    cmd.setAttribute("name", commandName);
    success.appendChild(cmd);

    Element parameter = outDoc.createElement("parameters");
    success.appendChild(parameter);

    Element output = outDoc.createElement("output");
    success.appendChild(output);
    return success;
}

From source file:Main.java

public static void addDataText1(Document doc, Node parent, String elementName, String elementData) {
    Element e = doc.createElement(elementName);
    e.appendChild(doc.createTextNode(elementData));
    parent.appendChild(e);//  w w w.j ava2  s  .c  o m
}

From source file:Main.java

public static Node createTextElement(Document doc, String name, String content) {
    Node elementNode = doc.createElement(name);
    Node textNode = doc.createTextNode(content);
    elementNode.appendChild(textNode);//from w  w w  .  j  a  v a  2 s.  c  o  m
    return elementNode;
}

From source file:Main.java

public static Element createElemWithText(Document ownerDoc, String tagName, String text) {
    Element newElem = ownerDoc.createElement(tagName);
    newElem.appendChild(ownerDoc.createTextNode(text));
    return newElem;
}

From source file:Util.java

/**
 * Cre un lment avec un Text Node comme enfant.
 * //from   w  ww  .ja v  a  2s .co m
 * @param doc
 * @param tagName
 * @param text
 * @return
 */
public static Element createElementWithText(final Document doc, final String tagName, final String text) {
    Element e = doc.createElement(tagName);
    e.appendChild(doc.createTextNode(text));
    return e;
}

From source file:Main.java

/**
 * Add a node at the end to a node./*  ww w. ja  v a2  s.c o  m*/
 * 
 * @param doc document
 * @param node parent node
 * @param name name of node
 * @return new node
 */
public static Element addNode(Document doc, Node node, String name) {
    Element element = doc.createElement(name);
    node.appendChild(element);
    return element;
}

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);
}

From source file:Main.java

public static Element createElemWithCDATA(Document ownerDoc, String tagName, String cdata) {
    Element newElem = ownerDoc.createElement(tagName);
    newElem.appendChild(ownerDoc.createCDATASection(cdata));
    return newElem;
}