Java XML Duration Add addTextElement(Node parent, String name, String value)

Here you can find the source of addTextElement(Node parent, String name, String value)

Description

add Text Element

License

LGPL

Declaration

public static Element addTextElement(Node parent, String name, String value) 

Method Source Code

//package com.java2s;
/*//  ww  w  .j  a  va2 s. c o m
 * JFox - The most lightweight Java EE Application Server!
 * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
 *
 * JFox is licenced and re-distributable under GNU LGPL.
 */

import org.w3c.dom.Attr;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {

    public static Element addTextElement(Node parent, String name, String value) {
        return addTextElement(parent, name, value, null);
    }

    public static Element addTextElement(Node parent, String name, String value, Attr[] attrs) {
        Element element;
        if (parent instanceof Document) {
            element = ((Document) parent).createElement(name);
        } else {
            element = parent.getOwnerDocument().createElement(name);
        }

        if (attrs != null && attrs.length > 0) {
            for (Attr attr : attrs) {
                element.setAttributeNode(attr);
            }
        }

        if (value != null) {
            element.setTextContent(value);
        }
        parent.appendChild(element);
        return element;
    }
}

Related

  1. addLongElementNS(Element parent, String namespaceURI, String tag, long value)
  2. addNamespacePrefix(Element parent, String namespace, String basePrefix)
  3. addNode(Element parent, String elementName, String namespaceURI)
  4. addNode(Node parentNode, String name)
  5. addText(Node parent, String value)
  6. appendElement(Element parent, String tagName)
  7. appendElement(Element parent, String tagName, String value)
  8. appendElement(Element parent, String type)
  9. appendElement(Node parent, String name)