Add an Element to XML Document - Java XML

Java examples for XML:DOM Document

Description

Add an Element to XML Document

Demo Code


//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Add an Element to a Document */
    public static Element addChildElement(Document doc, Node parent,
            String tag) {/*from w ww . j  a  v  a2s  . co m*/

        Element e = doc.createElement(tag);
        doc.importNode(e, true);
        parent.appendChild(e);
        return e;
    }
}

Related Tutorials