Java XML Duration Add appendElement(Node parent, String name)

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

Description

append Element

License

Open Source License

Declaration

public static Element appendElement(Node parent, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Element appendElement(Node parent, String name) {
        return appendElement(parent, name, null);
    }//from w ww.  j a  v a2s .c om

    public static Element appendElement(Node parent, String name, Object data, String... attributes) {
        Document doc = (parent.getNodeType() == Node.DOCUMENT_NODE) ? (Document) parent : parent.getOwnerDocument();
        Element e = doc.createElement(name);
        parent.appendChild(e);

        if (data != null)
            e.appendChild(doc.createTextNode(data.toString()));

        for (int i = 0; i < attributes.length; ++i)
            e.setAttribute(attributes[i++], attributes[i]);

        return e;
    }
}

Related

  1. addTextElement(Node parent, String name, String value)
  2. appendElement(Element parent, String tagName)
  3. appendElement(Element parent, String tagName, String value)
  4. appendElement(Element parent, String type)
  5. appendElement(Node parent, String name)
  6. appendElement(Node parent, String tagName)
  7. appendElementNS(Element parent, String namespaceURI, String localName)
  8. appendStringElement(Element parentElement, String nodeName, String nodeValue)
  9. appendText(Element parent, String content)