Package com.axelor.common
Class XMLUtils
java.lang.Object
com.axelor.common.XMLUtils
The
XMLUtils
provides various methods to deal with XML parsing.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilder
Returns properly configuredDocumentBuilder
with security features.static DocumentBuilderFactory
createDocumentBuilderFactory
(Boolean namespaceAware) Returns properly configuredDocumentBuilderFactory
with security features and no external DTD and schema access.static SAXParser
Returns properly configuredSAXParser
with security features and no external DTD and schema access.static SAXParserFactory
createSAXParserFactory
(Boolean namespaceAware) Returns properly configuredSAXParserFactory
with security features.static TransformerFactory
Returns properly configuredTransformerFactory
with security features.static XPath
Returns properly configuredXPath
with security featuresstatic XPathFactory
Returns properly configuredXPathFactory
with security features.Create anIterator
for the given nodes.static Document
Parse the content of the given file as an XML document.static Document
parse
(InputStream is) Parse the content of the givenInputStream
as an XML document.static Document
Parse the content of the givenReader
as an XML document.static Document
Parse the content of the given URI as an XML document.static Document
parse
(InputSource is) Parse the content of the givenInputSource
as an XML document.static Spliterator
<Node> spliterator
(NodeList nodes) Create aSpliterator
for the given nodes.Create aStream
of the nodes.Create aStream
of the child elements with the given tag name.static void
Transform the given node to xml content.
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
createDocumentBuilderFactory
Returns properly configuredDocumentBuilderFactory
with security features and no external DTD and schema access.- Parameters:
namespaceAware
- whether the returned factory is to provide support for XML namespaces- Returns:
- configured
DocumentBuilderFactory
-
createDocumentBuilder
Returns properly configuredDocumentBuilder
with security features.- Returns:
- configured
DocumentBuilder
- Throws:
ParserConfigurationException
-
createSAXParserFactory
Returns properly configuredSAXParserFactory
with security features.- Parameters:
namespaceAware
- whether the returned factory is to provide support for XML namespaces- Returns:
- configured
SAXParserFactory
-
createSAXParser
Returns properly configuredSAXParser
with security features and no external DTD and schema access.- Returns:
- configured
SAXParser
- Throws:
ParserConfigurationException
SAXException
-
createXPathFactory
Returns properly configuredXPathFactory
with security features.- Returns:
- configured
XPathFactory
-
createXPath
Returns properly configuredXPath
with security features- Returns:
- configured
XPath
-
createTransformerFactory
Returns properly configuredTransformerFactory
with security features.- Returns:
- configured
TransformerFactory
-
parse
public static Document parse(File file) throws ParserConfigurationException, SAXException, IOException Parse the content of the given file as an XML document.- Parameters:
file
- the file to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
-
parse
public static Document parse(InputStream is) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenInputStream
as an XML document.- Parameters:
is
- the InputStream to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
-
parse
public static Document parse(InputSource is) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenInputSource
as an XML document.- Parameters:
is
- the InputSource to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
-
parse
public static Document parse(Reader reader) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenReader
as an XML document.- Parameters:
reader
- the Reader to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
-
parse
public static Document parse(URI uri) throws ParserConfigurationException, SAXException, IOException Parse the content of the given URI as an XML document.- Parameters:
uri
- the location of the content to be parsed.- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationException
SAXException
IOException
- See Also:
-
transform
Transform the given node to xml content.- Parameters:
node
- the node to transformwriter
- the writer where to write the contentencoding
- encoding to user for xml content- Throws:
TransformerException
-
iterator
Create anIterator
for the given nodes.- Parameters:
nodes
- the nodes- Returns:
- an iterator
-
spliterator
Create aSpliterator
for the given nodes.- Parameters:
nodes
- the nodes- Returns:
- a spliterator
-
stream
Create aStream
of the nodes.- Parameters:
nodes
- the nodes- Returns:
- stream of the nodes
-
stream
Create aStream
of the child elements with the given tag name.- Parameters:
node
- the parent nodetagName
- the tag name of the child nodes, use"*"
for any elements- Returns:
- stream of the matching child elements
-