Java XML Transform Usage toNonValidatingSAXSource(InputStream in)

Here you can find the source of toNonValidatingSAXSource(InputStream in)

Description

Returns a SAXSource for the provided InputStream that explicitly forfeit external DTD validation

License

Apache License

Parameter

Parameter Description
in the InputStream for the SAXSource

Exception

Parameter Description
SAXException if a SAX error occurs
ParserConfigurationException if a configuration error occurs

Return

a for the provided that explicitly forfeit external DTD validation

Declaration

public static Source toNonValidatingSAXSource(InputStream in)
        throws SAXException, ParserConfigurationException 

Method Source Code


//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);
    }
}

Related

  1. path(Element element)
  2. readDoc(Reader in)
  3. renderElement(Element theElem)
  4. safeToXml(Element element)
  5. streamSource(File file)
  6. toXMLInputSource(StreamSource in)
  7. unwrapException(Throwable t)
  8. verifySignature(Element element, PublicKey validatingKey)
  9. writeElementContent(XMLInputFactory inputFactory, XMLStreamWriter writer, Element element)