Class XMLHelper

java.lang.Object
org.apache.poi.util.XMLHelper

@Internal public final class XMLHelper extends Object
Helper methods for working with javax.xml classes.
See Also:
  • Method Details

    • getDocumentBuilderFactory

      public static DocumentBuilderFactory getDocumentBuilderFactory()
      Creates a new DocumentBuilderFactory, with sensible defaults
    • newDocumentBuilder

      public static DocumentBuilder newDocumentBuilder()
      Creates a new document builder, with sensible defaults
      Throws:
      IllegalStateException - If creating the DocumentBuilder fails, e.g. due to ParserConfigurationException.
    • getSaxParserFactory

      public static SAXParserFactory getSaxParserFactory()
    • newXMLReader

      public static XMLReader newXMLReader() throws SAXException, ParserConfigurationException
      Creates a new SAX XMLReader, with sensible defaults
      Throws:
      SAXException
      ParserConfigurationException
    • newXMLInputFactory

      public static XMLInputFactory newXMLInputFactory()
      Creates a new StAX XMLInputFactory, with sensible defaults
    • newXMLOutputFactory

      public static XMLOutputFactory newXMLOutputFactory()
      Creates a new StAX XMLOutputFactory, with sensible defaults
    • newXMLEventFactory

      public static XMLEventFactory newXMLEventFactory()
      Creates a new StAX XMLEventFactory, with sensible defaults
    • getTransformerFactory

      public static TransformerFactory getTransformerFactory()
    • newTransformer

      public static Transformer newTransformer() throws TransformerConfigurationException
      Throws:
      TransformerConfigurationException
    • getSchemaFactory

      public static SchemaFactory getSchemaFactory()
    • getDepthOfChildNodes

      public static int getDepthOfChildNodes(Node node, int maxSupportedDepth) throws POIException
      Counts the depth of the DOM tree starting from the given node.
      Parameters:
      node - the node to check
      maxSupportedDepth - the maximum supported depth of the DOM tree
      Returns:
      the depth
      Throws:
      POIException - if the depth exceeds maxSupportedDepth
    • escapeXml

      public static String escapeXml(String value)
      Escapes the five predefined XML entities (& < > " ') in the supplied string so it can be safely embedded as XML element text or as a single- or double-quoted attribute value.

      This is intended for the rare cases where XML is assembled by hand; prefer building XML through a DOM/XMLStreamWriter where practical.

      Parameters:
      value - the string to escape, may be null
      Returns:
      the escaped string, or null if value was null
      Since:
      POI 6.0.0