create Empty XML Document - Java XML

Java examples for XML:DOM Document

Description

create Empty XML Document

Demo Code


//package com.java2s;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.w3c.dom.DOMImplementation;

public class Main {
    public static Document createEmptyDoc(String top) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();/*from  w ww .ja v a2 s  .  c om*/
        DocumentBuilder builder = factory.newDocumentBuilder();
        DOMImplementation impl = builder.getDOMImplementation();
        return impl.createDocument(null, top, null);
    }
}

Related Tutorials