Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:Main.java

/**
 * This is used to create a child node// www.  j a  v  a  2 s. com
 * 
 * @param document
 * @param parent
 * @param childName
 * @param childContents
 */
public static void addChildElement(Document document, Element parent, String childName, String childContents) {
    Element childElement = document.createElement(childName);
    childElement.setTextContent(childContents);
    parent.appendChild(childElement);
}

From source file:Main.java

/**
 * Creates an {@link Element} containing the given text
 * //www .ja  v a2  s  .co m
 * @param document the document to contain the new element
 * @param tagName the element's tag name (required)
 * @param text the text to set; can be <code>null</code> for none
 * @return a non-<code>null</code> element
 * @since 1.2.0
 */
public static Element createTextElement(final Document document, final String tagName, final String text) {
    final Element element = document.createElement(tagName);
    element.setTextContent(text);
    return element;
}

From source file:Main.java

public static Element appendElement(Element parent, String tagName, String value) {
    Element child = appendElement(parent, tagName);
    child.setTextContent(value);
    return child;
}

From source file:Main.java

public static Node createNode(Document document, String nodeName, String nodeValue) throws Exception {
    Element nodeElement = document.createElement("Property");
    nodeElement.setAttribute("name", nodeName);
    Element nodeValueElement = document.createElement("Value");
    nodeValueElement.setTextContent(nodeValue);
    nodeElement.appendChild(nodeValueElement);
    return nodeElement;
}

From source file:Main.java

/**
 * Add a child element with the given text contents to the specified element.
 * //w ww .  j  a  v  a2 s .c om
 * @param doc Document object, used to build new elements.
 * @param elem Element to append new child to.
 * @param childName Name of the new child element.
 * @param childText Text contents of the new child element.
 */
public static void addChildText(Document doc, Element elem, String childName, String childText) {
    Element newChild = doc.createElement(childName);
    newChild.setTextContent(childText);
    elem.appendChild(newChild);
}

From source file:Main.java

static public void textContentTag(Element parent, String tagName, String content) {
    Element tag = parent.getOwnerDocument().createElement(tagName);
    tag.setTextContent(content);
    parent.appendChild(tag);/*  www .  j a  v a2 s  . c  om*/
}

From source file:Main.java

private static Node addNodeWithText(final Document doc, final Element parent, String name, String text) {
    final Element child = doc.createElement(name);
    child.setTextContent(text);
    return parent.appendChild(child);
}

From source file:Main.java

public static Element addChildElement(Node parent, String elementName, String textContent) {
    Element element = addChildElement(parent, elementName);
    element.setTextContent(textContent);
    return element;
}

From source file:Main.java

public static void addTextNode(Element element, String tagName, String value) {
    if (value != null && !(value.equals(""))) {
        Element titleElement = element.getOwnerDocument().createElement(tagName);
        titleElement.setTextContent(value);
        element.appendChild(titleElement);
    }//from  w  w  w  . j a va 2  s . c  o m
}

From source file:Main.java

public static void appendString(Element xmlElement, String tagName, String value) {
    if (value == null)
        return;/*from w  ww  .  j  av  a  2 s  . co  m*/
    Document parentDocument = xmlElement.getOwnerDocument();
    Element newElement = parentDocument.createElement(tagName);
    newElement.setTextContent(value);
}