Java XML Parse Stream parse(DefaultHandler handler, InputStream in)

Here you can find the source of parse(DefaultHandler handler, InputStream in)

Description

Parse the XML data in the given input stream, using the specified handler object as both the content and error handler.

License

Open Source License

Parameter

Parameter Description
handler the SAX event handler
in the input stream containing the XML to be parsed

Declaration

public static void parse(DefaultHandler handler, InputStream in)
        throws IOException, ParserConfigurationException, SAXException 

Method Source Code


//package com.java2s;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import java.io.*;
import javax.xml.parsers.*;

public class Main {
    /** The factory from whence we obtain XMLReader objects */
    protected static SAXParserFactory _pfactory;

    /**//from   w w w. j  a  v a 2 s . com
     * Parse the XML data in the given input stream, using the
     * specified handler object as both the content and error handler.
     *
     * @param handler the SAX event handler
     * @param in the input stream containing the XML to be parsed
     */
    public static void parse(DefaultHandler handler, InputStream in)
            throws IOException, ParserConfigurationException, SAXException {
        XMLReader xr = _pfactory.newSAXParser().getXMLReader();

        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);

        xr.parse(new InputSource(in));
    }
}

Related

  1. getNextStartElement(XMLStreamReader parser)
  2. getParamStream(XMLOutputFactory outputFactory, XMLEventFactory eventFactory, XMLEventReader parser, XMLEvent paramEvent)
  3. parse(final InputStream in)
  4. parse(final InputStream inputStream)
  5. parse(final InputStream is)
  6. parse(InputStream anInputStream)