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 final void addNodeValue(Node node, String name, String value) {
    if (value != null) {
        Document doc = node.getOwnerDocument();
        Element e = doc.createElement(name);
        e.appendChild(doc.createTextNode(value));
        node.appendChild(e);// w  ww  . j  a  v a2  s. com
    }
}

From source file:Main.java

public static Element createNewTextElement(Node elem, String tag, String value) {// throws Exception {
    Document doc = elem.getOwnerDocument();
    Element res = doc.createElement(tag);
    Text content = doc.createTextNode(value);
    res.appendChild(content);//  ww  w  .j av a 2 s  . c om
    elem.appendChild(res);
    return res;
}

From source file:Main.java

public static Node addTag(Document doc, String index, String value) {
    org.w3c.dom.Element tag = doc.createElement(index);
    tag.appendChild(doc.createTextNode(value));
    return doc.appendChild(tag);
}

From source file:Main.java

public static void appendTextChild(Element parent, String tagname, String text) {
    if (text == null) {
        text = "";
    }/* ww w .  j a v a2  s  . co m*/
    Document doc = parent.getOwnerDocument();
    Element childElement = doc.createElement(tagname);
    Text textNode = doc.createTextNode(text);
    childElement.appendChild(textNode);
    parent.appendChild(childElement);
}

From source file:Main.java

public static void setTextContent(Element elem, String content) {
    Document doc = elem.getOwnerDocument();
    if ((content != null) && !content.equals("")) {
        Text textNode = doc.createTextNode(content);
        elem.appendChild(textNode);/*from w  w  w.  j ava  2  s  . com*/
    }
}

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 a2 s  .com
    return elementNode;
}

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);/* w ww.j  a v  a  2s  . c  om*/
}

From source file:Util.java

/**
 * Cre un lment avec un Text Node comme enfant.
 * /* w  w  w. j ava 2 s.c  o  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

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 w w. ja  v a 2  s.com

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