Here you can find the source of addElement(Node parent, String elementName)
Parameter | Description |
---|---|
parent | The parent to to which the new Element node is to be added. |
elementName | The name of the Element to be added. |
public static Element addElement(Node parent, String elementName)
//package com.java2s; // License as published by the Free Software Foundation; either import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**//from www .j av a2 s .c o m * Add an Element node to the supplied parent name. * @param parent The parent to to which the new Element node is to be added. * @param elementName The name of the Element to be added. * @return The new Element. */ public static Element addElement(Node parent, String elementName) { Element element = null; if (parent instanceof Document) { element = ((Document) parent).createElement(elementName); } else { element = parent.getOwnerDocument().createElement(elementName); } parent.appendChild(element); return element; } }