java.lang.Object
org.omnifaces.util.Xml
Collection of utility methods for the JAXP API in general.
This class is not listed in showcase! Should I use it?
This class is indeed intented for internal usage only. We won't add methods here on user request. We only add methods here once we encounter non-DRY code in OmniFaces codebase. The methods may be renamed/changed without notice.
We don't stop you from using it if you found it in the Javadoc and you think you find it useful, but you have to accept the risk that the method signatures can be changed without notice. This utility class exists because OmniFaces intends to be free of 3rd party dependencies.
- Since:
- 2.1
- Author:
- Bauke Scholtz
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentcreateDocument(List<URL> urls) Creates a single XMLDocumentbased on given URLs representing XML documents.static DocumentBuilderCreates an instance ofDocumentBuilderwhich doesn't validate, nor is namespace aware nor expands entity references and disables external entity processing (to keep it as lenient and secure as possible).static NodeListgetNodeList(Node node, XPath xpath, String expression) Convenience method to return a node list matching given XPath expression.getNodeTextContents(URL url, String expression) Convenience method to return a list of node text contents for given URL representing XML document matching given XPath expression.static StringgetTextContent(Node node) Convenience method to return trimmed text content of given node.static voidparseAndAppendChildren(DocumentBuilder builder, Document document, List<URL> urls) Parse the given URLs as a document using the given builder and then append all its child nodes to the given document.
-
Method Details
-
createDocument
Creates a single XMLDocumentbased on given URLs representing XML documents. All those XML documents are merged into a single root element namedroot.- Parameters:
urls- The URLs representing XML documents.- Returns:
- A single XML document containing all given XML documents.
- Throws:
IOException- When an I/O error occurs.SAXException- When a XML parsing error occurs.
-
createDocumentBuilder
Creates an instance ofDocumentBuilderwhich doesn't validate, nor is namespace aware nor expands entity references and disables external entity processing (to keep it as lenient and secure as possible).- Returns:
- A lenient instance of
DocumentBuilder.
-
parseAndAppendChildren
public static void parseAndAppendChildren(DocumentBuilder builder, Document document, List<URL> urls) throws IOException, SAXException Parse the given URLs as a document using the given builder and then append all its child nodes to the given document.- Parameters:
builder- The document builder.document- The document.urls- The URLs representing XML documents.- Throws:
IOException- When an I/O error occurs.SAXException- When a XML parsing error occurs.
-
getNodeList
public static NodeList getNodeList(Node node, XPath xpath, String expression) throws XPathExpressionException Convenience method to return a node list matching given XPath expression.- Parameters:
node- The node to return node list matching given XPath expression for.xpath- The XPath instance.expression- The XPath expression to match node list.- Returns:
- A node list matching given XPath expression
- Throws:
XPathExpressionException- When the XPath expression contains a syntax error.
-
getTextContent
Convenience method to return trimmed text content of given node. This usesgetFirstChild().getNodeValue()instead ofgetTextContent()to workaround some buggy JAXP implementations.- Parameters:
node- The node to return text content for.- Returns:
- Trimmed text content of given node.
-
getNodeTextContents
Convenience method to return a list of node text contents for given URL representing XML document matching given XPath expression.- Parameters:
url- The URL representing XML document.expression- The XPath expression to match node list whose text content has to be collected.- Returns:
- A list of node text contents.
- Since:
- 2.6.3
-