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 encodeString(Document doc, Element parent, String str, String namespaceURI,
        String qualifiedName) {//from  ww w.  ja va 2  s  .  com
    if (str != null) {
        Element elm = doc.createElementNS(namespaceURI, qualifiedName);
        Text strVal = doc.createTextNode(str);
        elm.appendChild(strVal);
        parent.appendChild(elm);
    }
}

From source file:Main.java

/**
 * Inserts a new value for an XML tag specified by <code>tagName</code> name
 * in a <code>Document</code> object.
 * // w w w.  j a  va2 s . c  o  m
 * @param doc
 *            Document object.
 * @param tagName
 *            Name of the tag as String.
 * @param tagValue
 *            Value of the tag as String.
 */
public static Element insertTagValue(Document doc, String tagName, String tagValue) {
    Element element = doc.createElement(tagName);
    doc.getDocumentElement().appendChild(element);
    if (tagValue != null) {
        element.appendChild(doc.createTextNode(tagValue));
    }
    return element;
}

From source file:Main.java

public static void createChildTextWithComment(Document paramDocument, Element paramElement, String paramString1,
        String paramString2, String paramString3) {
    Element localElement = paramDocument.createElement(paramString1);
    localElement.appendChild(paramDocument.createTextNode((paramString2 == null) ? "" : paramString2));
    Comment localComment = paramDocument.createComment(paramString3);
    paramElement.appendChild(localComment);
    paramElement.appendChild(localElement);
}

From source file:Main.java

public static Element createTextElement(Document document, String tag, String text) {
    if (document == null || tag == null || text == null) {
        return null;
    }//from w w  w.j  a v a  2  s  .c  om

    Element element = document.createElement(tag);
    Text textNode = document.createTextNode(text);
    element.appendChild(textNode);
    return element;
}

From source file:Main.java

/**
 * Inserts a new value for an XML tag specified by <code>tagName</code> name
 * in a <code>Element</code> object.
 * /*from  w w  w.j av  a  2s. c om*/
 * @param elementToAppend
 *            Element object.
 * @param tagName
 *            Name of the tag as String.
 * @param tagValue
 *            Value of the tag as String.
 */
public static Element insertTagInElement(Document document, Element elementToAppend, String tagName,
        String tagValue) {
    Element newElement = document.createElement(tagName);
    elementToAppend.appendChild(newElement);
    newElement.appendChild(document.createTextNode(tagValue));
    return newElement;
}

From source file:Main.java

public static Element createTextElement(final Document document, final String qName, final String content,
        final Optional<String> namespaceURI) {
    Element typeElement = createElement(document, qName, namespaceURI);
    typeElement.appendChild(document.createTextNode(content));
    return typeElement;
}

From source file:Main.java

/**
 * Helper method for creating slot key-value pairs in the GnuCash XML structure.
 * <p>This method is only a helper for creating slots whose values are of string type</p>
 * @param doc {@link org.w3c.dom.Document} for creating nodes
 * @param key Slot key as string//from ww  w .  j ava  2  s. c o m
 * @param value Slot value as String
 * @return Element node containing the key-value pair
 */
public static Element createSlot(Document doc, String key, String value, String valueType) {
    Element slotNode = doc.createElement(TAG_SLOT);
    Element slotKeyNode = doc.createElement(TAG_SLOT_KEY);
    slotKeyNode.appendChild(doc.createTextNode(key));
    Element slotValueNode = doc.createElement(TAG_SLOT_VALUE);
    slotValueNode.setAttribute(ATTR_KEY_TYPE, valueType);
    slotValueNode.appendChild(doc.createTextNode(value));
    slotNode.appendChild(slotKeyNode);
    slotNode.appendChild(slotValueNode);

    return slotNode;
}

From source file:Main.java

public static void appendChild(Document document, Node root, String name, String value) {
    Node node = document.createElement(name);
    node.appendChild(document.createTextNode(value != null ? value : ""));
    root.appendChild(node);/*  w  w w .  j  a v a 2 s.co  m*/
    return;
}

From source file:Main.java

/**
 * Appends a child element to the provided parent element.
 * This child element is created with the name and string value provided.
 *
 * @param parentElement the parent element
 * @param name the name for the child element to be created
 * @param value the string value to be assigned to the created child element
 * @return the newly created child element 
 *//*  ww w .j av a2s . co m*/
public static Element appendChildElement(final Element parentElement, final String name, final String value) {
    Document parentDocument = parentElement.getOwnerDocument();
    Element createElement = createElement(parentDocument, name);
    if (value != null) {
        createElement.appendChild(parentDocument.createTextNode(value));
    }
    parentElement.appendChild(createElement);
    return createElement;
}

From source file:Main.java

public static void append(Document doc, String name, String phone, String email) {
    Element personNode = doc.createElement("person");

    Element nameNode = doc.createElement("name");
    personNode.appendChild(nameNode);//from  w  w  w  .j a  va2  s . c o m
    Text nametextNode = doc.createTextNode(name);
    nameNode.appendChild(nametextNode);

    Element phoneNode = doc.createElement("phone");
    personNode.appendChild(phoneNode);
    Text phonetextNode = doc.createTextNode(phone);
    phoneNode.appendChild(phonetextNode);

    Element emailNode = doc.createElement("email");
    personNode.appendChild(emailNode);
    Text emailtextNode = doc.createTextNode(email);
    emailNode.appendChild(emailtextNode);

    Element root = doc.getDocumentElement();
    root.appendChild(personNode);
}