Java XML Document Create getDocument(String xml)

Here you can find the source of getDocument(String xml)

Description

get Document

License

Apache License

Declaration

public static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Main {
    private static DocumentBuilder builder = null;

    public static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException {

        return getDocumentBuilder().parse(xml);
    }/*www  .j  a  va  2s.  com*/

    public static Document getDocument(File xmlfile)
            throws ParserConfigurationException, SAXException, IOException {

        return getDocumentBuilder().parse(xmlfile);
    }

    private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
        if (builder == null) {
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
            builder = domFactory.newDocumentBuilder();
        }
        return builder;
    }
}

Related

  1. getDocument(String docPath)
  2. getDocument(String fileName)
  3. getDocument(String filePath)
  4. getDocument(String payload)
  5. getDocument(String xml)
  6. getDocument(String xmlDocument)
  7. getDocument(String xslName)
  8. getDocument(URL location, boolean validating, boolean namespaceAware)
  9. getNewDocument()