Java XML Child Element Add addElement(Element parent, Element childElement)

Here you can find the source of addElement(Element parent, Element childElement)

Description

add Element

License

LGPL

Declaration

public static Element addElement(Element parent, Element childElement) 

Method Source Code

//package com.java2s;
/*/*w w  w  . j  av  a  2s. co 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 addElement(Node parent, String name, 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);
            }
        }
        parent.appendChild(element);
        return element;
    }

    public static Element addElement(Element parent, Element childElement) {
        Node childNode = parent.getOwnerDocument().importNode(childElement, true);
        parent.appendChild(childNode);
        return parent;
    }
}

Related

  1. addChildElement(Node parent, String tag, String value)
  2. addChildElements(Node n, List elements)
  3. addChildNode(Node pNode, String name, String value)
  4. addChildren(Element element, List children)
  5. addElement(Element parent, Element child)
  6. addElementChildTo(Element parent, String nsURI, String qualifiedName)
  7. appendElement(Element parent, Element child)
  8. appendElement(Element parent, Element child)
  9. appendTextNode(Node parent, String child)