Java XML Document from Stream load(InputStream inputStream)

Here you can find the source of load(InputStream inputStream)

Description

load

License

Open Source License

Declaration

public static Document load(InputStream inputStream) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.InputStream;

public class Main {
    public static Document load(InputStream inputStream) throws Exception {
        return getDocumentBuilder().parse(inputStream);

    }//from ww  w. ja  v  a 2 s. c  o  m

    public static Document load(String uri) throws Exception {
        return getDocumentBuilder().parse(uri);
    }

    private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
        DocumentBuilder documentBuilder;

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

        documentBuilderFactory.setValidating(false); // dtd isn't available; would be nice to attempt to validate
        documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        documentBuilderFactory.setNamespaceAware(true);
        documentBuilder = documentBuilderFactory.newDocumentBuilder();

        return documentBuilder;
    }
}

Related

  1. getXML(InputStream stream)
  2. getXML(InputStream stream)
  3. load(InputStream data)
  4. load(InputStream stream)
  5. loadDocument(InputStream documentInputStream)
  6. loadDocument(InputStream documentInputStream)
  7. loadDocument(InputStream in)