Class XMLUtils
java.lang.Object
org.opengis.cite.cat20.dgiwg10.util.XMLUtils
Provides various utility methods for accessing or manipulating XML representations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NodeList
Evaluates an XPath 1.0 expression using the given context and returns the result as a node set.static Object
Evaluates an XPath expression using the given context and returns the result as the specified type.static int
parseAsInteger
(Node context, String xpath) Returns the selected valuestatic String
writeNodeToString
(Node node) Writes the content of a DOM Node to a string.
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
writeNodeToString
Writes the content of a DOM Node to a string. The XML declaration is omitted and the character encoding is set to "US-ASCII" (any character outside of this set is serialized as a numeric character reference).- Parameters:
node
- The DOM Node to be serialized.- Returns:
- A String representing the content of the given node.
-
evaluateXPath
public static NodeList evaluateXPath(Node context, String expr, Map<String, String> namespaceBindings) throws XPathExpressionExceptionEvaluates an XPath 1.0 expression using the given context and returns the result as a node set.- Parameters:
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 (seeNamespaceBindings.withStandardBindings()
.- Returns:
- A NodeList containing nodes that satisfy the expression (it may be empty).
- Throws:
XPathExpressionException
- If the expression cannot be evaluated for any reason.
-
evaluateXPath
public static Object evaluateXPath(Node context, String expr, Map<String, String> namespaceBindings, QName returnType) throws XPathExpressionExceptionEvaluates an XPath expression using the given context and returns the result as the specified type.Note: The Saxon implementation supports XPath 2.0 expressions when using the JAXP XPath APIs (the default implementation will throw an exception).
- Parameters:
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 (seeNamespaceBindings.withStandardBindings()
.returnType
- The desired return type (as declared inXPathConstants
).- Returns:
- The result converted to the desired returnType.
- Throws:
XPathExpressionException
- If the expression cannot be evaluated for any reason.
-
parseAsInteger
Returns the selected value- Parameters:
context
- The context node.xpath
- An XPath expression evaluating to an integer value.- Returns:
- the selected value as int, -1 if the value is not a valid integer
- Throws:
XPathExpressionException
- If the expression cannot be evaluated for any reason.
-