Class StaxUtils
java.lang.Object
eu.europa.ec.taxud.validation.utils.StaxUtils
StaxUtils contains common utilities to help with XPath evaluation and StAX parsing.-
Method Summary
Modifier and TypeMethodDescriptionstatic NodegetCurrentNode(Transformer t, XMLStreamReader xsr) Transforms the node currently under the cursor of theStAX readerinto a DOMNode.static NodegetXPathAsNode(Node node, XPath xpath, String expression) Evaluates an XPath and returns the result as aNode.static NodeListIterablegetXPathAsNodeList(Node node, XPath xpath, String expression) Evaluates an XPath and returns the result as aNodeList.static DoublegetXPathAsNumber(Node node, XPath xpath, String expression) Evaluates an XPath and returns the result as a Double.static StringgetXPathAsString(Node node, XPath xpath, String expression) Evaluates an XPath and returns the result as a String.static voidNormalizes theNode.
-
Method Details
-
getCurrentNode
Transforms the node currently under the cursor of theStAX readerinto a DOMNode. Note that this method advances the XMLStreamReader. You should check the return value ofXMLStreamReader.getEventType()before making your own progress in the stream.- Parameters:
t- ATransformerto perform the work.xsr- The StAX reader. Must lie at a START_ELEMENT.- Returns:
- A DOM
Node.
-
getXPathAsNode
Evaluates an XPath and returns the result as aNode.- Parameters:
node- The node to run the XPath against.xpath- The XPath evaluator.expression- The expression to query.- Returns:
- The resulting
Node.
-
getXPathAsString
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
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
Evaluates an XPath and returns the result as aNodeList.- Parameters:
node- The node to run the XPath against.xpath- The XPath evaluator.expression- The expression to query.- Returns:
- The resulting
NodeList.
-
normalize
Normalizes theNode.- 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.
- Parameters:
node- TheNodeto normalize
- Calls
-