Java Utililty Methods XML Document from Stream

List of utility methods to do XML Document from Stream

Description

The list of methods to do XML Document from Stream are organized into topic(s).

Method

DocumentgetXML(InputStream stream)
get XML
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
    return docFactory.newDocumentBuilder().parse(stream);
} catch (ParserConfigurationException e) {
    e.printStackTrace();
} catch (UnknownHostException e) {
    e.printStackTrace();
return null;
DocumentgetXML(InputStream stream)
Reads XML from a stream
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
    return docFactory.newDocumentBuilder().parse(stream);
} catch (ParserConfigurationException ignored) {
    System.out.println("getXML parser error v001");
} catch (UnknownHostException e) {
    System.out.println("getXML UnknowHost error v002");
return null;
Documentload(InputStream data)
load
try {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(data);
} catch (ParserConfigurationException e) {
    throw new RuntimeException(e.getMessage(), e);
Documentload(InputStream inputStream)
load
return getDocumentBuilder().parse(inputStream);
Documentload(InputStream stream)
load
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(stream);
DocumentloadDocument(InputStream documentInputStream)
Loads a DOM document from the given input stream.
try {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    return documentBuilderFactory.newDocumentBuilder().parse(documentInputStream);
} catch (ParserConfigurationException e) {
    throw new RuntimeException(e);
DocumentloadDocument(InputStream documentInputStream)
load Document
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder;
documentBuilder = documentBuilderFactory.newDocumentBuilder();
return documentBuilder.parse(documentInputStream);
DocumentloadDocument(InputStream in)
Method should be invoked only from unit tests
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer sbuf = new StringBuffer();
try {
    String line = null;
    while ((line = reader.readLine()) != null) {
        sbuf.append(line);
        sbuf.append(System.getProperty("line.separator"));
} finally {
    reader.close();
return loadDocument(sbuf.toString());
DocumentloadDocument(InputStream is)
XML DOM helper.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(is);
return doc;
DocumentloadDocument(InputStream is)
load Document
return getDefaultFactory().newDocumentBuilder().parse(is);