Class XmlUtil

java.lang.Object
opennlp.tools.util.XmlUtil

public class XmlUtil extends Object
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 Details

    • XmlUtil

      public XmlUtil()
  • Method Details

    • createDocumentBuilder

      public static DocumentBuilder createDocumentBuilder()
      Create a new DocumentBuilder which processes XML securely.
      Returns:
      A valid DocumentBuilder instance.
      Throws:
      IllegalStateException - Thrown if errors occurred creating the builder.
    • createSaxParser

      public static SAXParser createSaxParser()
      Create a new namespace-aware SAXParser which processes XML securely.
      Returns:
      A valid SAXParser instance.
      Throws:
      IllegalStateException - Thrown if errors occurred creating the parser.
    • createXmlStreamReader

      public static XMLStreamReader createXmlStreamReader(InputStream in) throws XMLStreamException
      Create a new XMLStreamReader which 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, open InputStream of XML.
      Returns:
      A valid XMLStreamReader instance positioned before the first event.
      Throws:
      XMLStreamException - Thrown if the stream does not start a well-formed document.
      Since:
      3.0.0
    • createXPath

      public static XPath createXPath()
      Create a new XPath which evaluates expressions securely, including those given an InputSource to parse.
      Returns:
      A valid XPath instance.
      Since:
      3.0.0