Class StaxUtils

java.lang.Object
eu.europa.ec.taxud.validation.utils.StaxUtils

public final class StaxUtils extends Object
StaxUtils contains common utilities to help with XPath evaluation and StAX parsing.
  • Method Details

    • getCurrentNode

      public static Node getCurrentNode(Transformer t, XMLStreamReader xsr)
      Transforms the node currently under the cursor of the StAX reader into a DOM Node. Note that this method advances the XMLStreamReader. You should check the return value of XMLStreamReader.getEventType() before making your own progress in the stream.

      Parameters:
      t - A Transformer to perform the work.
      xsr - The StAX reader. Must lie at a START_ELEMENT.
      Returns:
      A DOM Node.
    • getXPathAsNode

      public static Node getXPathAsNode(Node node, XPath xpath, String expression)
      Evaluates an XPath and returns the result as a Node.
      Parameters:
      node - The node to run the XPath against.
      xpath - The XPath evaluator.
      expression - The expression to query.
      Returns:
      The resulting Node.
    • getXPathAsString

      public static String getXPathAsString(Node node, XPath xpath, String expression)
      Evaluates an XPath and returns the result as a String.
      Parameters:
      node - The node to run the XPath against.
      xpath - The XPath evaluator.
      expression - The expression to query.
      Returns:
      The resulting String.
    • getXPathAsNumber

      public static Double getXPathAsNumber(Node node, XPath xpath, String expression)
      Evaluates an XPath and returns the result as a Double.
      Parameters:
      node - The node to run the XPath against.
      xpath - The XPath evaluator.
      expression - The expression to query.
      Returns:
      The resulting Double.
    • getXPathAsNodeList

      public static NodeListIterable getXPathAsNodeList(Node node, XPath xpath, String expression)
      Evaluates an XPath and returns the result as a NodeList.
      Parameters:
      node - The node to run the XPath against.
      xpath - The XPath evaluator.
      expression - The expression to query.
      Returns:
      The resulting NodeList.
    • normalize

      public static void normalize(Node node)
      Normalizes the Node.
      • Calls Node.normalize().
      • Removes all Text nodes that are not the only child of their parent. The AEOI XSD does not allow them, and it allows removing all ignorable whitespace.
      This is required as the StAX stack is not able to discard ignorable whitespace automatically.
      Parameters:
      node - The Node to normalize