create Xml Element and add to parent element - Java XML

Java examples for XML:DOM Element Create

Description

create Xml Element and add to parent element

Demo Code


//package com.java2s;

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

public class Main {
    public static final Element createXmlElement(Document xml,
            Element parent, String name) {
        Element e = xml.createElement(name);
        try {//from   ww w  . jav  a 2s  .c  om
            parent.appendChild(e);
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        return e;
    }
}

Related Tutorials