Package org.apache.poi.util
Class XMLHelper
java.lang.Object
org.apache.poi.util.XMLHelper
Helper methods for working with javax.xml classes.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscapes 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.static intgetDepthOfChildNodes(Node node, int maxSupportedDepth) Counts the depth of the DOM tree starting from the given node.static DocumentBuilderFactoryCreates a new DocumentBuilderFactory, with sensible defaultsstatic SAXParserFactorystatic SchemaFactorystatic TransformerFactorystatic DocumentBuilderCreates a new document builder, with sensible defaultsstatic Transformerstatic XMLEventFactoryCreates a new StAX XMLEventFactory, with sensible defaultsstatic XMLInputFactoryCreates a new StAX XMLInputFactory, with sensible defaultsstatic XMLOutputFactoryCreates a new StAX XMLOutputFactory, with sensible defaultsstatic XMLReaderCreates a new SAX XMLReader, with sensible defaults
-
Method Details
-
getDocumentBuilderFactory
Creates a new DocumentBuilderFactory, with sensible defaults -
newDocumentBuilder
Creates a new document builder, with sensible defaults- Throws:
IllegalStateException- If creating the DocumentBuilder fails, e.g. due toParserConfigurationException.
-
getSaxParserFactory
-
newXMLReader
Creates a new SAX XMLReader, with sensible defaults -
newXMLInputFactory
Creates a new StAX XMLInputFactory, with sensible defaults -
newXMLOutputFactory
Creates a new StAX XMLOutputFactory, with sensible defaults -
newXMLEventFactory
Creates a new StAX XMLEventFactory, with sensible defaults -
getTransformerFactory
-
newTransformer
-
getSchemaFactory
-
getDepthOfChildNodes
Counts the depth of the DOM tree starting from the given node.- Parameters:
node- the node to checkmaxSupportedDepth- the maximum supported depth of the DOM tree- Returns:
- the depth
- Throws:
POIException- if the depth exceedsmaxSupportedDepth
-
escapeXml
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/
XMLStreamWriterwhere practical.- Parameters:
value- the string to escape, may benull- Returns:
- the escaped string, or
nullifvaluewasnull - Since:
- POI 6.0.0
-