Java XML Child Element Create addElement(final Document doc, final Node parent, final String name)

Here you can find the source of addElement(final Document doc, final Node parent, final String name)

Description

Adds an element to the specified document.

License

Open Source License

Parameter

Parameter Description
doc the document.
parent the parent node.
name the element name.

Return

the element.

Declaration

public static Element addElement(final Document doc, final Node parent, final String name) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*from w ww . ja  v a 2 s.  c om*/
     * Adds an element to the specified document.
     * @param doc the document.
     * @param parent the parent node.
     * @param name the element name.
     * @return the element.
     */
    public static Element addElement(final Document doc, final Node parent, final String name) {
        Element element = doc.createElement(name);
        if (parent != null) {
            parent.appendChild(element);
        } else {
            doc.appendChild(element);
        }
        return element;
    }
}

Related

  1. addElement(Document doc, Element rootElement, String elementName, String typeIn, String isArrayIn, String partitionerIn)
  2. addElement(Document doc, Node parent, String element)
  3. addElement(Document doc, String name, Element parent)
  4. addElement(Document document, Element father, String name, String attOneName, String attOneValue, String attTwoName, String attTwoValue)
  5. addElement(Document document, Element parentElement, String elementName, String elementValue)
  6. addElement(final Document document, final Element parentDom, final String namespace, final String name)
  7. addElement(final Document document, final Element parentDom, final String namespace, final String name)
  8. addElement(final Document document, final Element root, final String elementValue, final String elementName)
  9. addElement(final Document dom, final Element el, final String name, final String value)