public final class Xml extends Object
Collection of utility methods for the JAXP API in general.
Modifier and Type | Method and Description |
---|---|
static Document |
createDocument(List<URL> urls)
Creates a single XML
Document based on given URLs representing XML documents. |
static DocumentBuilder |
createDocumentBuilder()
Creates an instance of
DocumentBuilder which 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 NodeList |
getNodeList(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 String |
getTextContent(Node node)
Convenience method to return trimmed text content of given node.
|
static void |
parseAndAppendChildren(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.
|
public static Document createDocument(List<URL> urls) throws IOException, SAXException
Document
based on given URLs representing XML documents. All those XML documents
are merged into a single root element named root
.urls
- The URLs representing XML documents.IOException
- When an I/O error occurs.SAXException
- When a XML parsing error occurs.public static DocumentBuilder createDocumentBuilder()
DocumentBuilder
which 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).DocumentBuilder
.public static void parseAndAppendChildren(DocumentBuilder builder, Document document, List<URL> urls) throws IOException, SAXException
builder
- The document builder.document
- The document.urls
- The URLs representing XML documents.IOException
- When an I/O error occurs.SAXException
- When a XML parsing error occurs.public static NodeList getNodeList(Node node, XPath xpath, String expression) throws XPathExpressionException
node
- The node to return node list matching given XPath expression for.xpath
- The XPath instance.expression
- The XPath expression to match node list.XPathExpressionException
- When the XPath expression contains a syntax error.public static String getTextContent(Node node)
getFirstChild().getNodeValue()
instead of getTextContent()
to workaround some buggy
JAXP implementations.node
- The node to return text content for.public static List<String> getNodeTextContents(URL url, String expression)
url
- The URL representing XML document.expression
- The XPath expression to match node list whose text content has to be collected.Copyright © 2012–2020 OmniFaces. All rights reserved.