Example usage for org.w3c.dom Document createTextNode

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

Introduction

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

Prototype

public Text createTextNode(String data);

Source Link

Document

Creates a Text node given the specified string.

Usage

From source file:Main.java

public static void createTextChildElement(Document doc, Node node, String name, String value) {
    Element element = createChildElement(doc, node, name);
    element.appendChild(doc.createTextNode(value));
}

From source file:Main.java

/**
 * Creates a new element//from   w  w w. ja va 2s.  c  o 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 void addChild(final Document doc, Element parent, final String childName,
        final String childValue) {
    Element child = doc.createElement(childName);
    Text text = doc.createTextNode(childValue);
    child.appendChild(text);//w ww.j ava  2s  . c  o  m
    parent.appendChild(child);
}

From source file:Main.java

/**
 * Create a new element belonging to a namespace with specified text value.
 * //from   w w w. ja v a2  s .c om
 * @param document
 * @param nodeName
 * @param textValue
 * @return created element
 */
public static Element createElementNS(Document document, String namespaceURI, String nodeName,
        String textValue) {
    Element element = document.createElementNS(namespaceURI, nodeName);
    Node textNode = document.createTextNode(textValue);
    element.appendChild(textNode);
    return element;
}

From source file:Main.java

public static Element getElementWithText(Document doc, String elementName, String textValue) {
    Element elem_text = doc.createElement(elementName);
    elem_text.appendChild(doc.createTextNode(textValue));

    return elem_text;
}

From source file:Main.java

/**
 * internal function for adding an element to the DOM tree.
 *//*w w w .  j  av a 2 s .  c o  m*/
private static void addNode(Document doc, String elemName, String value) {
    Element root = doc.getDocumentElement();
    Element elem = doc.createElement(elemName);
    elem.appendChild(doc.createTextNode(value));
    root.appendChild(elem);
}

From source file:Main.java

public static void edit(Document doc) {

    Element root = doc.createElementNS(null, "person"); // Create Root Element
    Element item = doc.createElementNS(null, "name"); // Create element
    item.appendChild(doc.createTextNode("Jeff"));
    root.appendChild(item); // Attach element to Root element
    item = doc.createElementNS(null, "age"); // Create another Element
    item.appendChild(doc.createTextNode("28"));
    root.appendChild(item); // Attach Element to previous element down tree
    item = doc.createElementNS(null, "height");
    item.appendChild(doc.createTextNode("1.80"));
    root.appendChild(item); // Attach another Element - grandaugther
    doc.appendChild(root); // Add Root to Document
}

From source file:Main.java

public static void addNode(Document doc, Node parent, String ns, String name, String text, Map NS_MAP) {
    Element child = doc.createElementNS((String) NS_MAP.get(ns), ns + ":" + name);
    child.appendChild(doc.createTextNode(text));
    parent.appendChild(child);/*from ww w . j  a va 2  s  . co  m*/
}

From source file:Main.java

/**
 *
 * @param doc Document//from w w  w.j a v  a  2  s.co  m
 * @param parent Node
 * @param name String
 * @param value int
 * @return Element
 */
public static Element appendChildNode(Document doc, Node parent, String name, int value) {
    Element child = doc.createElement(name);
    child.appendChild(doc.createTextNode(new Integer(value).toString()));
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static Element addChildElement(Element element, String name, String text) {
    Document document = element.getOwnerDocument();
    Element result = (Element) element.appendChild(document.createElement(name));
    if (text != null)
        result.appendChild(document.createTextNode(text));

    return result;
}