Java XML Attribute Add addTextElement(Node parent, String name, String value, Attr[] attrs)

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

Description

add Text Element

License

LGPL

Declaration

public static Element addTextElement(Node parent, String name, String value, Attr[] attrs) 

Method Source Code

//package com.java2s;
/*//  w  ww.j a  v  a 2 s . c om
 * 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. addNewElementWithAttribute(Node node, String elementName, String elementValue, String attrName, String attrValue)
  2. addOptionalPropertyReference(BeanDefinitionBuilder builder, String propertyName, Attr attribute, String defaultValue)
  3. addOrUpdateAttribute(Element element, String name, String value)
  4. addPropertyReferenceIfNeeded(BeanDefinitionBuilder bdb, Element element, String attributeName)
  5. addRequiredPropertyValue(BeanDefinitionBuilder builder, String propertyName, Element element, String attributeName)
  6. addTypeAttribute(Element element, String type)
  7. readDoubleAttr(Element element, String attributeName, double defaultValue)