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 appendTextElement(Document doc, Element element, String key, String value) {
    Element newElement = doc.createElement(key);
    newElement.appendChild(doc.createTextNode(value));
    element.appendChild(newElement);//ww w  .j av a 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);/*  ww  w  .  ja v a2 s  . c o m*/
    file.getDocumentElement().appendChild(newNode);
    file.getDocumentElement().appendChild(file.createTextNode("\n  "));
}

From source file:Main.java

private static Element makePersonNode(Document doc, String name, String phone) {
    Element nameNode = doc.createElement("name");
    Text nametextNode = doc.createTextNode(name);
    nameNode.appendChild(nametextNode);//from w ww .  j a  v a  2  s . c o m

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

    Element personNode = doc.createElement("person");
    personNode.appendChild(nameNode);
    personNode.appendChild(phoneNode);
    return (personNode);
}

From source file:Main.java

public static Element newElement(Document document, String tagName) {
    return document.createElement(tagName);
}

From source file:Main.java

/**
 * Creates an element with the specified tag and appends it to the element supplied
 * @param element - the element to add the created element to
 * @param tag - the tag name for the element to create
 * @return The element created// w  w w.java  2s  .  co m
 */
public static Element appendElement(Element element, String tag) {
    Document document = element.getOwnerDocument();
    Element childElement = document.createElement(tag);
    element.appendChild(childElement);
    return childElement;
}

From source file:Main.java

/**
 * Create a node with tag name.//w w w  .  j a  va 2  s.  com
 * 
 * @param document
 *          the document
 * @param parent
 *          the parent node
 * @param tagName
 *          the tag name
 * @return the created node
 */
public static Element createNode(Document document, Node parent, String tagName) {
    Element node = document.createElement(tagName);
    parent.appendChild(node);
    return node;
}

From source file:Main.java

public static void addToXMLDoc(Document _doc, Element _element, String _tag, String _text) {
    Element child = _doc.createElement(_tag);
    _element.appendChild(child);/* w w w  . j ava  2  s .  c  om*/
    Text childText = _doc.createTextNode(_text);
    child.appendChild(childText);
}

From source file:Main.java

public static void addCdataNode(Element element, String tagName, String value) {
    if (value != null && !(value.equals(""))) {
        Document document = element.getOwnerDocument();
        Element titleElement = document.createElement(tagName);
        titleElement.appendChild(document.createCDATASection(value));
        element.appendChild(titleElement);
    }/*from w  w w  . ja  v a 2  s . c o m*/
}

From source file:Main.java

public static Element toXML(Color c, Document document) {
    Element result = document.createElement("color");

    String name;//from   w w w  .j  a  va  2  s  .c om
    if (c.equals(Color.WHITE)) {
        name = "white";
    } else if (c.equals(Color.CYAN)) {
        name = "cyan";
    } else if (c.equals(Color.YELLOW)) {
        name = "yellow";
    } else if (c.equals(Color.PINK)) {
        name = "pink";
    } else if (c.equals(Color.GREEN)) {
        name = "green";
    } else {
        name = "white";
    }

    result.setAttribute("name", name);

    return result;
}

From source file:Main.java

public static Element appendChildElement(Element parentNode, String nodeName) {
    Document doc = parentNode.getOwnerDocument();
    Element childNode = doc.createElement(nodeName);
    parentNode.appendChild(childNode);//from w w  w  . j  a v a2 s  .  c  o m
    return childNode;
}