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

/**
 * create an element from a document, that has some text content in it
 * @param doc - document/*from   w  w w  .  j a  v  a2  s  . com*/
 * @param name - element name
 * @param attributes - attribute map
 * @param content - string content
 * @return element object
 */
public static Element createElement(Document doc, String name, Map<String, String> attributes, String content) {
    Element e = createElement(doc, name, attributes);
    e.appendChild(doc.createTextNode(content));
    return e;
}

From source file:Main.java

/**
 *
 * @param doc Document//w  ww.ja v a2s .c  om
 * @param parent Node
 * @param name String
 * @param value String
 * @return Element
 */
public static Element appendChildNode(Document doc, Node parent, String name, String value) {
    Element child = doc.createElement(name);
    child.appendChild(doc.createTextNode(value));
    parent.appendChild(child);
    return child;
}

From source file:Main.java

/**
 * Creates a new element, with the given text inside that element.
 * /*from w  w  w  . ja  v a  2 s  .c  om*/
 * @param document the document into which the element is added.
 * @param parentElement The parent element of the element-to-be-added.
 * @param newElementName name of new element (tag-name).
 * @param textString the text to be written inside the newly created element.
 * @return The new element.
 */
public static Element addElementWithText(Document document, Element parentElement, String newElementName,
        String textString) {
    Element newElement = document.createElement(newElementName);
    Text text = document.createTextNode(textString);
    newElement.appendChild(text);
    parentElement.appendChild(newElement);
    return newElement;
}

From source file:Main.java

public static Element createSimpleTextElementWithoutNS(final Document documentParent,
        final String elementTagName, final String elementText) {
    Element element = documentParent.createElement(elementTagName);
    element.appendChild(documentParent.createTextNode(elementText));
    return element;
}

From source file:Main.java

public static void createOptionalChildText(Document doc, Element elem, String name, String value) {
    if (value == null || value.length() == 0) {
        return;//from w  w w  .  j  a v  a2s  .  co m
    }
    Element child = doc.createElement(name);
    child.appendChild(doc.createTextNode(value));
    elem.appendChild(child);
}

From source file:Main.java

public static Element writeStringElement(Document document, String name, String value, Element parentElement) {
    Element element = document.createElement(name);
    if (value == null) {
        value = "null";
    }//from  w w w.j  a va2 s .c  om
    Text text = document.createTextNode(value);
    element.appendChild(text);
    parentElement.appendChild(element);
    return element;
}

From source file:Main.java

public static void writeStringElement(Document document, Element parentElement, String elementTagName,
        String elementValue) {// w w w.jav a2 s. c o  m
    Element stringElement = createChildElement(document, parentElement, elementTagName);
    Text textNode = document.createTextNode(elementValue);
    stringElement.appendChild(textNode);
}

From source file:Main.java

public static void createElementAndAppend(String name, int value, Document doc, Element appendeeElement,
        String attributeName, String attributeValue) {
    Element newElement = doc.createElement(name);
    Text text = doc.createTextNode(String.valueOf(value));
    newElement.appendChild(text);//from   w  w  w.j a  v a2  s  .com
    if (attributeName != null && !attributeName.equals("")) {
        newElement.setAttribute(attributeName, attributeValue);
    }
    appendeeElement.appendChild(newElement);
}

From source file:Main.java

public static void createElementAndAppend(String name, double value, Document doc, Element appendeeElement,
        String attributeName, String attributeValue) {
    Element newElement = doc.createElement(name);
    Text text = doc.createTextNode(String.valueOf(value));
    newElement.appendChild(text);//  ww w .j a v a2  s. com
    if (attributeName != null && !attributeName.equals("")) {
        newElement.setAttribute(attributeName, attributeValue);
    }
    appendeeElement.appendChild(newElement);
}

From source file:Main.java

public static Element createTextElement(Element parent, String tagName, String text) {
    Document doc = parent.getOwnerDocument();
    Element e = createElement(parent, tagName);
    if (text == null) {
        text = "";
    }//from   w w w.ja v a 2  s  .c  om
    e.appendChild(doc.createTextNode(text));
    return e;
}