Package org.opengis.cite.iso19142.util

# Class XMLUtils

java.lang.Object
org.opengis.cite.iso19142.util.XMLUtils

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `XMLUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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 String`
  `expandReferencesInText(String value)`
  Expands character entity (&name;) and numeric references ( &#xhhhh; or &dddd;) that occur within a given string value.
  `static Node`
  `getElementByNamespaceURIandLocalPart(Node node, String namespaceURI, String localPart)`
  Returns a descendant Element node having the specified [namespace name] and [local part] property.
  `static List<Element>`
  `getElementsByNamespaceURI(Node node, String namespaceURI)`
  Returns a List of all descendant Element nodes having the specified [namespace name] property.
  `static QName`
  `getQName(Node node)`
  Returns the qualified name of a DOM node.
  `static String`
  `resultToString(Result result)`
  Writes the result of a transformation to a String.
  `static Document`
  `transform(Source xslt, Node source, Map<String,String> params)`
  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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### XMLUtils

    public XMLUtils()

- ## Method Details

  - ### writeNodeToString

    public static String writeNodeToString(Node node)
    Writes the content of a DOM node to a String. An XML declaration is omitted.
    Parameters:
      `node` - The node to be serialized.
    Returns:
      A String representing the content of the given node.

  - ### resultToString

    public static String resultToString(Result result)
    Writes the result of a transformation to a String. An XML declaration is always omitted.
    Parameters:
      `result` - An object (DOMResult or StreamResult) that holds the result of a transformation, which may be XML or plain text.
    Returns:
      A String representing the content of the result; it may be empty if the content could not be read.

  - ### writeNode

    public static void writeNode(Node node, OutputStream outputStream)
    Writes the content of a DOM node to a byte stream. An XML declaration is omitted.
    Parameters:
      `node` - The node to be serialized.
      `outputStream` - The destination OutputStream reference.

  - ### 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.

  - ### evaluateXPath2

    public static net.sf.saxon.s9api.XdmValue evaluateXPath2(Source xmlSource, String expr, Map<String,String> nsBindings) throws net.sf.saxon.s9api.SaxonApiException
    Evaluates an XPath 2.0 expression using the Saxon s9api interfaces.
    Parameters:
      `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. A namespace binding for "gml" may be omitted.
    Returns:
      An XdmValue object representing a value in the XDM data model; this is a sequence of zero or more items, where each item is either an atomic value or a node.
    Throws:
      `net.sf.saxon.s9api.SaxonApiException` - If an error occurs while evaluating the expression; this always wraps some other underlying exception.

  - ### createElement

    public static Element createElement(QName qName)
    Creates a new Element having the specified qualified name. The element must be `adopted` when inserted into another Document.
    Parameters:
      `qName` - A QName object.
    Returns:
      An Element node (with a Document owner but no parent).

  - ### getElementsByNamespaceURI

    public static List<Element> getElementsByNamespaceURI(Node node, String namespaceURI)
    Returns a List of all descendant Element nodes having the specified [namespace name] property. The elements are listed in document order.
    Parameters:
      `node` - The node to search from.
      `namespaceURI` - An absolute URI denoting a namespace name.
    Returns:
      A List containing elements in the specified namespace; the list is empty if there are no elements in the namespace.

  - ### getElementByNamespaceURIandLocalPart

    public static Node getElementByNamespaceURIandLocalPart(Node node, String namespaceURI, String localPart)
    Returns a descendant Element node having the specified [namespace name] and [local part] property.
    Parameters:
      `node` - The node to search from.
      `namespaceURI` - An absolute URI denoting a namespace name.
      `localPart` - The local part.
    Returns:
      The matching Node with the specified namespace and local part; null, if no matching node is found.

  - ### transform

    public static Document transform(Source xslt, Node source, Map<String,String> params)
    Transforms the content of a DOM Node using a specified XSLT stylesheet.
    Parameters:
      `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.
      `params` - A Map containing global stylesheet parameters (name-value pairs).
    Returns:
      A DOM Document containing the result of the transformation.

  - ### expandReferencesInText

    public static String expandReferencesInText(String value)
    Expands character entity (&name;) and numeric references ( &#xhhhh; or &dddd;) that occur within a given string value. It may be necessary to do this before processing an XPath expression.
    Parameters:
      `value` - A string representing text content.
    Returns:
      A string with all included references expanded.

  - ### getQName

    public static QName getQName(Node node)
    Returns the qualified name of a DOM node.
    Parameters:
      `node` - A DOM node.
    Returns:
      A QName representing a qualified name.