- java.lang.Object
- 
- org.omnifaces.util.Xml
 
- 
 public final class Xml extends Object 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 SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static DocumentcreateDocument(List<URL> urls)Creates a single XMLDocumentbased on given URLs representing XML documents.static DocumentBuildercreateDocumentBuilder()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).static NodeListgetNodeList(Node node, XPath xpath, String expression)Convenience method to return a node list matching given XPath expression.static List<String>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 Detail- 
createDocumentpublic static Document createDocument(List<URL> urls) throws IOException, SAXException 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.
 
 - 
createDocumentBuilderpublic static DocumentBuilder 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.
 
 - 
parseAndAppendChildrenpublic 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.
 
 - 
getNodeListpublic 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.
 
 - 
getTextContentpublic static String getTextContent(Node node) 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.
 
 - 
getNodeTextContentspublic static List<String> 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.- 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
 
 
- 
 
-