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 createElement(Element parent, String elementName, String text) {
    Document doc = parent.getOwnerDocument();
    Element id = doc.createElement(elementName);
    id.setTextContent(text);//from  ww w .ja  va2s.  c o  m
    parent.appendChild(id);
}

From source file:Main.java

public static Element toXML(Point p, Document document) {
    Element result = document.createElement("center");
    result.setAttribute("x", Integer.toString(p.x));
    result.setAttribute("y", Integer.toString(p.y));
    return result;
}

From source file:Main.java

public final static Document newDocument(String rootElementName) {
    Document doc = newDocument();
    doc.appendChild(doc.createElement(rootElementName));

    return doc;/* w  w  w . java 2  s. c  om*/
}

From source file:Main.java

private static Node createElementWithCDATA(Document doc, String tagName, String cdata) {
    Element node = doc.createElement(tagName);
    node.appendChild(doc.createCDATASection(cdata));

    return node;/*from   w  w  w .  j  av a 2  s .  c  o  m*/
}

From source file:Main.java

public static final void addNodeCDATAValue(Node node, String name, String value) {
    if (value != null) {
        Document doc = node.getOwnerDocument();
        Element e = doc.createElement(name);
        e.appendChild(doc.createCDATASection(value));
        node.appendChild(e);//from  w  w w. j  a v a 2  s  .c om
    }
}

From source file:Main.java

private static Element createElementWithContent(Document doc, String tagName, String content) {
    Element node = doc.createElement(tagName);
    node.appendChild(doc.createTextNode(content));

    return node;/*from  ww w.j a  va 2s.  c o m*/
}

From source file:Main.java

public static Element addElement(Document doc, String name, Element parent) {
    Element ee = doc.createElement(name);
    parent.appendChild(ee);// ww  w  .ja  v a2s .co  m
    return ee;
}

From source file:Main.java

public static Element createElement(Element parent, String tagName) {
    Document doc = parent.getOwnerDocument();
    Element child = doc.createElement(tagName);
    parent.appendChild(child);//from w w  w  .  ja  v  a  2  s  .  c o  m
    return child;
}

From source file:Main.java

/**
 * Creates an element representing {@code <tag>text</tag>}.
 *
 * @param doc//from ww w.  j  a v a2 s .c o  m
 *            The {@link Document} containing the {@link Element}.
 * @param tag
 *            The tag name of the created {@link Element}.
 * @param text
 *            The content of the created {@link Element}.
 * @return the {@link Element} created.
 */
public static Element createField(Document doc, String tag, String text) {
    Element elem = doc.createElement(tag);
    elem.appendChild(doc.createTextNode(text));
    return elem;
}

From source file:Main.java

public static Node getMagicNode(Document doc, String content) {
    Element magicNode = doc.createElement("KMagicNode");
    magicNode.appendChild(doc.createCDATASection(content));
    return magicNode;
}