Here you can find the source of parse(final InputStream inputStream)
Parameter | Description |
---|---|
inputStream | the InputStream to parse from |
Parameter | Description |
---|---|
SAXException | if the XML source is not valid |
IOException | if the source could not be read |
ParserConfigurationException | if the parser could not be created |
public static Document parse(final InputStream inputStream) throws SAXException, IOException, ParserConfigurationException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { private static DocumentBuilderFactory _dbf = DocumentBuilderFactory.newInstance(); /**/*from w w w . j a v a2 s.c o m*/ * Parses a new XML {@link Document} from a given {@link InputSource} * * @param inputSource * the {@link InputSource} to parse from * @return the parsed {@link Document} * @throws SAXException * if the XML source is not valid * @throws IOException * if the source could not be read * @throws ParserConfigurationException * if the parser could not be created */ public static Document parse(final InputSource inputSource) throws SAXException, IOException, ParserConfigurationException { return newDocumentBuilder().parse(inputSource); } /** * Parses a new XML {@link Document} from a given {@link InputStream} * * @param inputStream * the {@link InputStream} to parse from * @return the parsed {@link Document} * @throws SAXException * if the XML source is not valid * @throws IOException * if the source could not be read * @throws ParserConfigurationException * if the parser could not be created */ public static Document parse(final InputStream inputStream) throws SAXException, IOException, ParserConfigurationException { return parse(new InputSource(inputStream)); } /** * Parses a new XML {@link Document} from a given {@link Reader} * * @param reader * the {@link Reader} to parse from * @return the parsed {@link Document} * @throws SAXException * if the XML source is not valid * @throws IOException * if the source could not be read * @throws ParserConfigurationException * if the parser could not be created */ public static Document parse(final Reader reader) throws SAXException, IOException, ParserConfigurationException { return parse(new InputSource(reader)); } /** * Parses a new XML {@link Document} from a given XML {@link String}. * * @param xmlContent * the XML {@link String} to parse from * @return the parsed {@link Document} * @throws SAXException * if the XML source is not valid * @throws IOException * if the source could not be read * @throws ParserConfigurationException * if the parser could not be created */ public static Document parse(final String xmlContent) throws SAXException, IOException, ParserConfigurationException { return parse(new StringReader(xmlContent)); } /** * Creates and returns a new {@link DocumentBuilder}. * * @return a new {@link DocumentBuilder} * @throws ParserConfigurationException * if the creation fails */ public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { return _dbf.newDocumentBuilder(); } }