Java XML Document from Stream readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error)

Here you can find the source of readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error)

Description

read XML

License

Open Source License

Declaration

public static Document readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2010 Oracle//from  w ww. j a  v a  2s  . co  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Original file was copied from
 * org.eclipse.wst.common.project.facet.core.util.internal.FileUtil
 *
 ******************************************************************************/

import java.io.ByteArrayInputStream;

import java.io.InputStream;

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

import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;

public class Main {
    public static Document readXML(InputStream inputStream, EntityResolver resolver, ErrorHandler error) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db;

        try {
            db = dbf.newDocumentBuilder();

            if (resolver != null) {
                db.setEntityResolver(resolver);
            }

            if (error != null) {
                db.setErrorHandler(error);
            }

            return db.parse(inputStream);
        } catch (Throwable SWTBot) {
            return null;
        }
    }

    public static Document readXML(String content) {
        return readXML(new ByteArrayInputStream(content.getBytes()), null, null);
    }
}

Related

  1. loadXmlDocumentFromStream(@Nonnull InputStream in)
  2. loadXMLFrom(final InputStream is)
  3. loadXmlFromInputSource(InputSource is)
  4. readXML(InputStream input)
  5. readXml(InputStream inputStream)
  6. readXML(InputStream inStream)
  7. readXML(InputStream is)