Class XmlUtil
java.lang.Object
opennlp.tools.util.XmlUtil
Creates XML parsers that process untrusted input securely.
Every factory comes from
Apache Commons Secure XML.
The parsers it creates fetch no external resource unless an EntityResolver
explicitly allows it, and they bound entity expansion. Its
threat model
lists the settings a caller may still change without weakening these guarantees.
- Since:
- 1.8.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilderCreate a newDocumentBuilderwhich processes XML securely.static SAXParserCreate a new namespace-awareSAXParserwhich processes XML securely.static XMLStreamReaderCreate a newXMLStreamReaderwhich processes XML securely.static XPathCreate a newXPathwhich evaluates expressions securely, including those given anInputSourceto parse.
-
Constructor Details
-
XmlUtil
public XmlUtil()
-
-
Method Details
-
createDocumentBuilder
Create a newDocumentBuilderwhich processes XML securely.- Returns:
- A valid
DocumentBuilderinstance. - Throws:
IllegalStateException- Thrown if errors occurred creating the builder.
-
createSaxParser
Create a new namespace-awareSAXParserwhich processes XML securely.- Returns:
- A valid
SAXParserinstance. - Throws:
IllegalStateException- Thrown if errors occurred creating the parser.
-
createXmlStreamReader
Create a newXMLStreamReaderwhich processes XML securely.The reader coalesces adjacent text sections.
The returned reader respects the StAX contract and does not close the underlying input stream, regardless of the implementation on the classpath.
- Parameters:
in- A valid, openInputStreamof XML.- Returns:
- A valid
XMLStreamReaderinstance positioned before the first event. - Throws:
XMLStreamException- Thrown if the stream does not start a well-formed document.- Since:
- 3.0.0
-
createXPath
Create a newXPathwhich evaluates expressions securely, including those given anInputSourceto parse.- Returns:
- A valid
XPathinstance. - Since:
- 3.0.0
-