Java XML Child Element Create createChildElement(final String tagName, final Node parent, final Document document)

Here you can find the source of createChildElement(final String tagName, final Node parent, final Document document)

Description

Creates a child element with the given name and parent.

License

Open Source License

Parameter

Parameter Description
tagName the name of the new child (required)
parent the parent node (required)
document the document to which the parent and child belong (required)

Return

the created element

Declaration

public static Element createChildElement(final String tagName,
        final Node parent, final Document document) 

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 {
    /**// ww w  .  j  ava2s  . c o  m
     * Creates a child element with the given name and parent. Avoids the type
     * of bug whereby the developer calls {@link Document#createElement(String)}
     * but forgets to append it to the relevant parent.
     * 
     * @param tagName the name of the new child (required)
     * @param parent the parent node (required)
     * @param document the document to which the parent and child belong
     *            (required)
     * @return the created element
     * @since 1.2.0
     */
    public static Element createChildElement(final String tagName,
            final Node parent, final Document document) {
        final Element child = document.createElement(tagName);
        parent.appendChild(child);
        return child;
    }
}

Related

  1. createChildElement(Document doc, Element parent, String name)
  2. createChildElement(Document doc, Node node, String nodeName)
  3. createChildElement(Element parent, String name)
  4. createChildElement(Element parentElement, String elementName)
  5. createChildElement(Element parentElement, String strTagName)
  6. createChildElement(String tagName, Element parentElement)
  7. createTextChild(Node elem, String elemName, Boolean text)
  8. getChildElementByChain(Element element, String[] chain, boolean create)
  9. getOrCreateChildNode(IIOMetadataNode parentNode, String name)