new Document with namespace aware - Android XML

Android examples for XML:Namespace

Description

new Document with namespace aware

Demo Code


//package com.java2s;

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

import org.w3c.dom.Document;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(newDocument());
    }//from  ww w  .  j a va 2 s .c om

    public static Document newDocument()
            throws ParserConfigurationException {
        return newDocumentBuilder().newDocument();
    }

    private static DocumentBuilder newDocumentBuilder()
            throws ParserConfigurationException {
        // SAXParsers are not concurrency compatible, so always return a new instance to prevent thread issues 
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        return dbf.newDocumentBuilder();
    }
}

Related Tutorials