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

public static Element createElement(Element element, String tagName, String text) {
    Document doc = element.getOwnerDocument();
    Element child = doc.createElement(tagName);
    if (text != null)
        child.setTextContent(text);
    element.appendChild(child);/*from  ww w  .j  av  a  2s .  c  o m*/
    return child;
}

From source file:Main.java

/**
 * Creates an element with the specified tag with the text as its content and appends it to the element supplied
 * @param element - the element to add the created element to
 * @param tag - the tag name for the element to create
 * @param text - the text to have as the content of the created Element
 * @return The element created//from   w w  w.ja  v a  2 s .c o m
 */
public static Element appendTextElement(Element element, String tag, String text) {
    Element childElement = appendElement(element, tag);
    childElement.setTextContent(text);
    return childElement;
}

From source file:Main.java

public static void insertValue(Element parent, String childName, String childNamespace, String value) {
    Element child = parent.getOwnerDocument().createElementNS(childNamespace, childName);
    child.setTextContent(value);
    parent.appendChild(child);/*www  .j a  v a  2  s  .c  o  m*/
}

From source file:Main.java

public static void appendChild(Document doc, Node parentNode, String childName, String childContents) {
    if (childContents == null)
        throw (new NullPointerException("ChildNode is null."));

    Element child = doc.createElement(childName);
    child.setTextContent(childContents);
    parentNode.appendChild(child);/*  w w w  . j  a  v a2 s  . c o m*/
}

From source file:Main.java

public static Element addElement(Element parent, String childName, String textValue, Document doc) {
    Element childElement = doc.createElementNS(DEFAULT_NAMESPACE, childName);
    childElement.setTextContent(textValue);
    parent.appendChild(childElement);/*w w  w  .j  a v a  2  s.  c  o  m*/
    return childElement;
}

From source file:Main.java

public static Element addElement(Document document, Element parentElement, String elementName,
        String elementValue) {//from www .  j  av  a 2s . co m
    Element childElement = addElement(document, parentElement, elementName);
    childElement.setTextContent(elementValue);
    return childElement;
}

From source file:Main.java

/**
 * Appends the child element as well as value to the parent element.
 * //from w  ww. j a  v  a 2  s . c o  m
 * @param parent the parent element
 * @param tagName the child element name
 * @param value the child element value
 * @return the child element added to the parent element
 */
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

static public void booleanContentTag(Element parent, String tagName, boolean content) {
    Element tag = parent.getOwnerDocument().createElement(tagName);
    if (content)/* w  w w.  j  a va2s .co  m*/
        tag.setTextContent("1");
    else
        tag.setTextContent("0");
    parent.appendChild(tag);
}

From source file:Main.java

/**
 * Creates an element with a given text content
 *///from w w  w . j  a v  a2s .  co m
public static Element createElement(Element parent, Document document, String name, String value) {
    Element element = createElement(parent, document, name);
    element.setTextContent(value);
    return element;
}

From source file:Main.java

/**
 * A helper method for quick property saving/modification. If the property element does not exist, it is automatically created.
 *
 * @param element The parent element.//from   w w w . j  a  v a2s .c  o m
 * @param name The property name.
 * @param value The property value
 * @return
 */
public static void quickPropertyWrite(Element element, String name, String value) {
    NodeList nodeList = element.getElementsByTagName(name);
    if (nodeList.getLength() == 1) {
        nodeList.item(0).setTextContent(value);
    } else {
        Element newProp = element.getOwnerDocument().createElement(name);
        newProp.setTextContent(value);
        element.appendChild(newProp);
    }
}