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 DocumentBuilderReturns properly configuredDocumentBuilderwith security features.static DocumentBuilderFactorycreateDocumentBuilderFactory(Boolean namespaceAware) Returns properly configuredDocumentBuilderFactorywith security features and no external DTD and schema access.static SAXParserReturns properly configuredSAXParserwith security features and no external DTD and schema access.static SAXParserFactorycreateSAXParserFactory(Boolean namespaceAware) Returns properly configuredSAXParserFactorywith security features.static TransformerFactoryReturns properly configuredTransformerFactorywith security features.static XPathReturns properly configuredXPathwith security featuresstatic XPathFactoryReturns properly configuredXPathFactorywith security features.Create anIteratorfor the given nodes.static DocumentParse the content of the given file as an XML document.static Documentparse(InputStream is) Parse the content of the givenInputStreamas an XML document.static DocumentParse the content of the givenReaderas an XML document.static DocumentParse the content of the given URI as an XML document.static Documentparse(InputSource is) Parse the content of the givenInputSourceas an XML document.static Spliterator<Node> spliterator(NodeList nodes) Create aSpliteratorfor the given nodes.Create aStreamof the nodes.Create aStreamof the child elements with the given tag name.static voidTransform the given node to xml content.
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
createDocumentBuilderFactory
Returns properly configuredDocumentBuilderFactorywith 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 configuredDocumentBuilderwith security features.- Returns:
- configured
DocumentBuilder - Throws:
ParserConfigurationException
-
createSAXParserFactory
Returns properly configuredSAXParserFactorywith security features.- Parameters:
namespaceAware- whether the returned factory is to provide support for XML namespaces- Returns:
- configured
SAXParserFactory
-
createSAXParser
Returns properly configuredSAXParserwith security features and no external DTD and schema access.- Returns:
- configured
SAXParser - Throws:
ParserConfigurationExceptionSAXException
-
createXPathFactory
Returns properly configuredXPathFactorywith security features.- Returns:
- configured
XPathFactory
-
createXPath
Returns properly configuredXPathwith security features- Returns:
- configured
XPath
-
createTransformerFactory
Returns properly configuredTransformerFactorywith 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:
ParserConfigurationExceptionSAXExceptionIOException- See Also:
-
parse
public static Document parse(InputStream is) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenInputStreamas an XML document.- Parameters:
is- the InputStream to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException- See Also:
-
parse
public static Document parse(InputSource is) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenInputSourceas an XML document.- Parameters:
is- the InputSource to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException- See Also:
-
parse
public static Document parse(Reader reader) throws ParserConfigurationException, SAXException, IOException Parse the content of the givenReaderas an XML document.- Parameters:
reader- the Reader to parse- Returns:
- A new DOM Document object.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
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:
ParserConfigurationExceptionSAXExceptionIOException- 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 anIteratorfor the given nodes.- Parameters:
nodes- the nodes- Returns:
- an iterator
-
spliterator
Create aSpliteratorfor the given nodes.- Parameters:
nodes- the nodes- Returns:
- a spliterator
-
stream
Create aStreamof the nodes.- Parameters:
nodes- the nodes- Returns:
- stream of the nodes
-
stream
Create aStreamof 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
-