Class XMLUtils

java.lang.Object
org.opengis.cite.cat20.dgiwg10.util.XMLUtils

public class XMLUtils extends Object
Provides various utility methods for accessing or manipulating XML representations.
  • Constructor Details

    • XMLUtils

      public XMLUtils()
  • Method Details

    • writeNodeToString

      public static String writeNodeToString(Node node)
      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 XPathExpressionException
      Evaluates 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 (see NamespaceBindings.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 XPathExpressionException
      Evaluates 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 (see NamespaceBindings.withStandardBindings().
      returnType - The desired return type (as declared in XPathConstants ).
      Returns:
      The result converted to the desired returnType.
      Throws:
      XPathExpressionException - If the expression cannot be evaluated for any reason.
    • parseAsInteger

      public static int parseAsInteger(Node context, String xpath) throws XPathExpressionException
      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.