public class XMLUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
XMLUtils.ResultHolder<T>
This class is used with the processElements method.
|
Modifier and Type | Field and Description |
---|---|
protected XMLInputFactory |
xmlInputFactory |
Constructor and Description |
---|
XMLUtils() |
protected XMLInputFactory xmlInputFactory
public static XMLUtils getInstance()
public String format(Source sourceXml, TransformerProperties transformProperties)
sourceXml
- to transform a given SourcetransformProperties
- settings for transformerpublic String format(Node nodeXml, TransformerProperties transformerProperties)
nodeXml
- to transform a given NodetransformerProperties
- settings for transformerpublic String prettyFormat(Source sourceXml)
sourceXml
- to transform a given Sourcepublic String prettyFormat(Node nodeXml)
nodeXml
- to transform a given Nodepublic Result transform(Source sourceXml, TransformerProperties transformProperties, Result result)
sourceXml
- to transform a given SourcetransformProperties
- settings for transformerresult
- Result to transform intopublic Result transform(Node nodeXml, TransformerProperties transformerProperties, Result result)
nodeXml
- to transform a given NodetransformerProperties
- settings for transformerresult
- Result to transform intopublic String getRootNamespace(String xml)
xml
- The XML whose root namespace you wantpublic <T> T processElements(String xml, BiFunction<XMLUtils.ResultHolder<T>,XMLStreamReader,Boolean> processElementFunction)
If the function returns true, processing continues to the next element. When the last element in the document is processed, the value in the result is returned.
If the lambda function returns false, processing stops. The value of the result is returned.
If the function encounters a processing exception, processing stops and null is returned.
xml
- The XML to processprocessElementFunction
- Function that accepts an instance of XMLStreamReader and result
holder. The function must return a boolean.public XMLInputFactory getSecureXmlInputFactory()
public DocumentBuilderFactory getSecureDocumentBuilderFactory(String className, ClassLoader classLoader)
public DocumentBuilderFactory getSecureDocumentBuilderFactory()
public DocumentBuilder getSecureDocumentBuilder(boolean namespaceAware) throws ParserConfigurationException
ParserConfigurationException
public Document parseDocument(InputStream inputStream, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException
public TransformerFactory getSecureXmlTransformerFactory(String className, ClassLoader classLoader)
public TransformerFactory getSecureXmlTransformerFactory()
public Transformer getXmlTransformer(boolean omitXml) throws TransformerException
TransformerException
public SAXParserFactory getSecureSAXParserFactory(String className, ClassLoader classLoader)
public SAXParserFactory getSecureSAXParserFactory()
public SAXParser getSecureSAXParser(boolean namespaceAware) throws ParserConfigurationException, SAXException
public XMLReader getSecureXmlParser(String className) throws SAXException
SAXException
public XMLReader getSecureXmlParser() throws SAXException
SAXException
This work is licensed under a Creative Commons Attribution 4.0 International License.