View Javadoc

1   package eu.ehri.project.exporters.xml;
2   
3   import org.w3c.dom.Document;
4   import org.xml.sax.SAXException;
5   
6   import javax.xml.parsers.DocumentBuilder;
7   import javax.xml.parsers.DocumentBuilderFactory;
8   import javax.xml.parsers.ParserConfigurationException;
9   import java.io.IOException;
10  import java.io.InputStream;
11  
12  /**
13   * Helper for reading XML documents from a stream.
14   */
15  public class DocumentReader {
16      public Document read(InputStream inputStream) throws ParserConfigurationException, IOException, SAXException {
17          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
18          factory.setValidating(false);
19          factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
20          factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
21          DocumentBuilder documentBuilder = factory.newDocumentBuilder();
22          return documentBuilder.parse(inputStream);
23      }
24  }