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 Element createFailure(Document outputDoc, String commandName, String type) {
    Element failure = outputDoc.createElement("failure");
    failure.setAttribute("type", type);
    Element cmd = outputDoc.createElement("command");
    cmd.setAttribute("name", commandName);
    failure.appendChild(cmd);//from w  w w.j  a  va 2s  .co m

    Element parameter = outputDoc.createElement("parameters");
    failure.appendChild(parameter);

    // Element output = outputDoc.createElement("output");
    // failure.appendChild(output);
    return failure;
}

From source file:Main.java

public static Element createChild(Document paramDocument, Element paramElement, String paramString) {
    Element localElement = paramDocument.createElement(paramString);
    paramElement.appendChild(localElement);
    return localElement;
}

From source file:Main.java

public static Element writeFloatElement(Document document, String name, float value, Element parentElement) {
    Element element = document.createElement(name);
    Text text = document.createTextNode(Float.toString(value));
    element.appendChild(text);//ww w  .  j ava 2  s  . c o  m
    parentElement.appendChild(element);
    return element;
}

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);//from ww w . j  a  v  a 2 s  . co m
    parent.appendChild(name);
}

From source file:Main.java

/**
 * Adds an element to the specified document.
 * @param doc the document./*w  ww.j  av  a 2  s. com*/
 * @param parent the parent node.
 * @param name the element name.
 * @return the element.
 */
public static Element addElement(final Document doc, final Node parent, final String name) {
    Element element = doc.createElement(name);
    if (parent != null) {
        parent.appendChild(element);
    } else {
        doc.appendChild(element);
    }
    return element;
}

From source file:Main.java

/**
 * Creates a new element// www .  jav  a2s.  co m
 * 
 * @param doc
 * @param tag
 * @param data
 * @return
 */
public static Element createElement(Document doc, String tag, String data) {
    Element receiverEmail = doc.createElement(tag);
    if (data != null) {
        Text receiverEmailText = doc.createTextNode(data);
        receiverEmail.appendChild(receiverEmailText);
    }
    return receiverEmail;
}

From source file:Main.java

public static Element createElement(Element parent, String name) {
    Document document;
    Element element;/*w  w  w. j av  a  2s . co  m*/

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

    parent.appendChild(element);
    return element;
}

From source file:Main.java

public static void append(Document doc, String name, String phone, String email) {
    Element personNode = doc.createElement("person");

    Element nameNode = doc.createElement("name");
    personNode.appendChild(nameNode);/*  ww w.j ava 2s .c  om*/
    Text nametextNode = doc.createTextNode(name);
    nameNode.appendChild(nametextNode);

    Element phoneNode = doc.createElement("phone");
    personNode.appendChild(phoneNode);
    Text phonetextNode = doc.createTextNode(phone);
    phoneNode.appendChild(phonetextNode);

    Element emailNode = doc.createElement("email");
    personNode.appendChild(emailNode);
    Text emailtextNode = doc.createTextNode(email);
    emailNode.appendChild(emailtextNode);

    Element root = doc.getDocumentElement();
    root.appendChild(personNode);
}

From source file:Main.java

/**
 * Creates an element without text content
 *//*  www.j  av  a  2s.c  o  m*/
public static Element createElement(Element parent, Document document, String name) {
    Element element = document.createElement(name);
    parent.appendChild(element);
    return element;
}

From source file:Main.java

/**
 * Creates a new {@link Document}.//from w w w . j av a2 s . co  m
 *
 * @param rootElementName The name of the root element.
 * @param xmlns The namespace of the document.
 * @return Returns said {@link Document}.
 */
public static Document createDocument(String rootElementName, String xmlns) {
    final Document doc = createDocument();
    final Element root = doc.createElement(rootElementName);
    if (xmlns != null)
        root.setAttribute("xmlns", xmlns);
    doc.appendChild(root);
    return doc;
}