Java XML DOM Parse parseDom(InputStream byteArrayInputStream)

Here you can find the source of parseDom(InputStream byteArrayInputStream)

Description

parse Dom

License

Apache License

Declaration

public static Document parseDom(InputStream byteArrayInputStream) 

Method Source Code

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

import java.io.InputStream;

import java.io.Reader;

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

import org.w3c.dom.Document;

public class Main {
    /**/* w w  w  .j ava2  s .  c o  m*/
     * Document builder factory
     */
    private static DocumentBuilderFactory factory = null;

    /**
     * Creates a DOM from a file representation of an xml record
     * 
     * @param reader
     *            the xml reader
     * @return the DOM document
     */
    public static Document parseDom(Reader reader) {
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new org.xml.sax.InputSource(reader));
        } catch (Exception e) {
            throw new RuntimeException("Could not parse DOM for '" + reader.toString() + "'!", e);
        }
    }

    public static Document parseDom(InputStream byteArrayInputStream) {

        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new org.xml.sax.InputSource(byteArrayInputStream));
        } catch (Exception e) {
            throw new RuntimeException("Could not parse DOM for '" + byteArrayInputStream.toString() + "'!", e);
        }

    }
}

Related

  1. parse_XML_String_and_create_DOM(String xmlData)
  2. parseDom(Reader reader)
  3. parseDOMConfigFile(String folderPath, String configFileName)
  4. parseDomFromFile(File doc)
  5. parseFileToXML(Transformer transformer, DOMSource source, File file)