Here you can find the source of toNonValidatingSAXSource(InputStream in)
Parameter | Description |
---|---|
in | the InputStream for the SAXSource |
Parameter | Description |
---|---|
SAXException | if a SAX error occurs |
ParserConfigurationException | if a configuration error occurs |
public static Source toNonValidatingSAXSource(InputStream in) throws SAXException, ParserConfigurationException
//package com.java2s; /*/*from www. j av a 2s . c o m*/ * Copyright 2017 Frederic Thevenet * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Source; import javax.xml.transform.sax.SAXSource; import java.io.*; public class Main { /** * Returns a {@link SAXSource} for the provided {@link InputStream} that explicitly forfeit external DTD validation * * @param in the {@link InputStream} for the {@link SAXSource} * @return a {@link SAXSource} for the provided {@link InputStream} that explicitly forfeit external DTD validation * @throws SAXException if a SAX error occurs * @throws ParserConfigurationException if a configuration error occurs */ public static Source toNonValidatingSAXSource(InputStream in) throws SAXException, ParserConfigurationException { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); XMLReader xmlReader = spf.newSAXParser().getXMLReader(); InputSource inputSource = new InputSource(in); return new SAXSource(xmlReader, inputSource); } }