Here you can find the source of createChildElement(final String tagName, final Node parent, final Document document)
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) |
public static Element createChildElement(final String tagName, final Node parent, final Document document)
//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; } }