public class XMLUtils extends Object
| Constructor and Description |
|---|
XMLUtils() |
| Modifier and Type | Method and Description |
|---|---|
static List<Node> |
asList(NodeList nodeList)
Returns a List view of the nodes in the given NodeList collection.
|
static Element |
createElement(QName qName)
Creates a new Element having the specified qualified name.
|
static NodeList |
evaluateXPath(Node context,
String expr,
Map<String,String> namespaceBindings)
Evaluates an XPath 1.0 expression using the given context and returns the
result as a node set.
|
static Object |
evaluateXPath(Node context,
String expr,
Map<String,String> namespaceBindings,
QName returnType)
Evaluates an XPath expression using the given context and returns the
result as the specified type.
|
static net.sf.saxon.s9api.XdmValue |
evaluateXPath2(Source xmlSource,
String expr,
Map<String,String> nsBindings)
Evaluates an XPath 2.0 expression using the Saxon s9api interfaces.
|
static net.sf.saxon.s9api.XdmValue |
evaluateXQuery(Source source,
String query,
Map<String,String> nsBindings)
Evaluates an XQuery 1.0 expression using the Saxon s9api interfaces.
|
static String |
expandReferencesInText(String value)
Expands character entity (&name;) and numeric references (
&#xhhhh; or &dddd;) that occur within a given
string value.
|
static List<Element> |
getElementsByNamespaceURI(Node node,
String namespaceURI)
Returns a List of all descendant Element nodes having the specified
[namespace name] property.
|
static Document |
importElement(Element elem)
Creates a DOM Document with the given Element as the document element.
|
static Document |
transform(Source xslt,
Node source)
Transforms the content of a DOM Node using a specified XSLT stylesheet.
|
static void |
writeNode(Node node,
OutputStream outputStream)
Writes the content of a DOM Node to a byte stream.
|
static String |
writeNodeToString(Node node)
Writes the content of a DOM Node to a string.
|
public static String writeNodeToString(Node node)
node - The DOM Node to be serialized.public static void writeNode(Node node, OutputStream outputStream)
node - The DOM Node to be serialized.outputStream - The destination OutputStream reference.public static NodeList evaluateXPath(Node context, String expr, Map<String,String> namespaceBindings) throws XPathExpressionException
context - The context node.expr - An XPath expression.namespaceBindings - A collection of namespace bindings for the XPath expression,
where each entry maps a namespace URI (key) to a prefix
(value). Standard bindings do not need to be declared (see
NamespaceBindings.withStandardBindings().XPathExpressionException - If the expression cannot be evaluated for any reason.public static Object evaluateXPath(Node context, String expr, Map<String,String> namespaceBindings, QName returnType) throws XPathExpressionException
Note: The Saxon implementation supports XPath 2.0 expressions when using the JAXP XPath APIs (the default implementation will throw an exception).
context - The context node.expr - An XPath expression.namespaceBindings - A collection of namespace bindings for the XPath expression,
where each entry maps a namespace URI (key) to a prefix
(value). Standard bindings do not need to be declared (see
NamespaceBindings.withStandardBindings().returnType - The desired return type (as declared in XPathConstants
).XPathExpressionException - If the expression cannot be evaluated for any reason.public static net.sf.saxon.s9api.XdmValue evaluateXPath2(Source xmlSource, String expr, Map<String,String> nsBindings) throws net.sf.saxon.s9api.SaxonApiException
xmlSource - The XML Source.expr - The XPath expression to be evaluated.nsBindings - A collection of namespace bindings required to evaluate the
XPath expression, where each entry maps a namespace URI (key)
to a prefix (value); this may be null if not needed.net.sf.saxon.s9api.SaxonApiException - If an error occurs while evaluating the expression; this
always wraps some other underlying exception.public static net.sf.saxon.s9api.XdmValue evaluateXQuery(Source source, String query, Map<String,String> nsBindings) throws net.sf.saxon.s9api.SaxonApiException
source - The XML Source.query - The query expression.nsBindings - A collection of namespace bindings required to evaluate the
query, where each entry maps a namespace URI (key) to a prefix
(value).net.sf.saxon.s9api.SaxonApiException - If an error occurs while evaluating the query (this always
wraps some other underlying exception).public static Element createElement(QName qName)
adopted when inserted into
another Document.qName - A QName object.public static List<Element> getElementsByNamespaceURI(Node node, String namespaceURI)
node - The node to search from.namespaceURI - An absolute URI denoting a namespace name.public static Document transform(Source xslt, Node source)
xslt - A Source object representing a stylesheet (XSLT 1.0 or 2.0).source - A Node representing the XML source. If it is an Element node
it will be imported into a new DOM Document.public static String expandReferencesInText(String value)
value - A string representing text content.public static Document importElement(Element elem)
elem - An Element node.Copyright © 2023 Open Geospatial Consortium. All rights reserved.