Interface IXPath
-
- All Known Implementing Classes:
XPathImpl
@StableMinor(version="14.1", sinceVersion="8.1") public interface IXPath
Document
navigator helper.- Since:
- 8.1.0
- Version:
- $Revision: 24683 $ $Date: 2021-08-23 18:55:58 -0300 (Mon, 23 Aug 2021) $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<String,Object>
getMap(String xpath)
Selects a node with the given XPath and converts it to aMap
, by usingtoMap(Node)
.Map<String,Object>
getMap(String xpath, Node context)
Selects a node with the given XPath and converts it to aMap
, by usingtoMap(Node)
.List<Map<String,Object>>
getMaps(String xpath)
Selects nodes with the given XPath and converts them to aList
ofMap
, by usingtoMap(Node)
in each of these nodes.List<Map<String,Object>>
getMaps(String xpath, Node context)
Selects nodes with the given XPath and converts them to aList
ofMap
, by usingtoMap(Node)
in each of these nodes.List<Node>
selectNodes(String xpath)
Returns anode list
with the selected nodes by the given XPath using the document in context.List<Node>
selectNodes(String xpath, Node context)
Returns anode list
with the selected nodes by the given XPath in the givencontext
.Node
selectSingleNode(String xpath)
Returns a single node selected by the given XPath expression using the document in context.Node
selectSingleNode(String xpath, Node context)
Returns a single node selected by the given XPath expression in the givencontext
.Map<String,Object>
toMap(Node node)
Returns a Map object based on the given node.String
valueOf(String xpath, Node context)
Returns the string representation of the evaluated XPath in the given context.
-
-
-
Method Detail
-
valueOf
String valueOf(String xpath, Node context)
Returns the string representation of the evaluated XPath in the given context.- Parameters:
xpath
- the XPath expression.context
- the context node.- Returns:
- the string representation of the evaluated XPath in the given context.
- Since:
- 8.1.0
-
selectNodes
List<Node> selectNodes(String xpath)
Returns anode list
with the selected nodes by the given XPath using the document in context.- Parameters:
xpath
- the XPath expression.- Returns:
- a
node list
with the selected nodes by the given XPath. - Since:
- 8.1.0
-
selectNodes
List<Node> selectNodes(String xpath, Node context)
Returns anode list
with the selected nodes by the given XPath in the givencontext
.- Parameters:
xpath
- the XPath expression.context
- the context node.- Returns:
- a
node list
with the selected nodes by the given XPath. - Since:
- 8.1.0
-
selectSingleNode
Node selectSingleNode(String xpath)
Returns a single node selected by the given XPath expression using the document in context. If more than one node is selected, the first one is returned. If there's no such node,null
is returned.- Parameters:
xpath
- the XPath expression.- Returns:
- a single node selected by the given XPath expression
- Since:
- 8.1.0
-
selectSingleNode
Node selectSingleNode(String xpath, Node context)
Returns a single node selected by the given XPath expression in the givencontext
. If more than one node is selected, the first one is returned. If there's no such node,null
is returned.- Parameters:
xpath
- the XPath expression.context
- the context node.- Returns:
- a single node selected by the given XPath expression
- Since:
- 8.1.0
-
toMap
Map<String,Object> toMap(Node node)
Returns a Map object based on the given node.The conversion rules are as follows:
- Elements
-
A XML element node will behave depending on its nature.
If the element node is a simple element node, then its value will become available under the node name.
For example, the given XML node:
Some textanother text var myValue = myMap.myNode;
, the variablemyValue
will have the valueSome textother textanother text
.
It is important to notice that no white space will be automatically included between text and CDATA nodes.If the element node is a simple element node with attributes, then its value will become available under the
$
object, inside the node object.
For example, the given XML node:
Some textanother text var myValue = myMap.myNode.$;
, the variablemyValue
will have the valueSome textother textanother text
.
It is important to notice that no white space will be automatically included between text and CDATA nodes.If the node is a complex node then its text (inner
CDATA sections
andtext nodes
) will not be accessible. This kind of node is simply a container for inner nodes.
For example, the given XML node:
Some textanother text Other node text myNode
will not be accessible at all and the text of nodemyOtherNode
will be accessible usingmyMap.myNode.myOtherNode
.Another aspect of element nodes is when they are automatically wrapped in arrays. It happens in the following situations:
- If some element node has at least one sibling node with the very same name.
- If an element node has the attribute
lumIsArray
with the valuetrue
. - If the parent node of some element node has a name that is the concatenation of the child node with the "s" suffix and the child element node either doesn't have the
lumIsArray
attribute or the value oflumIsArray
attribute is notfalse
. - If the element node has the name
row
and its parent node name isdata
and the child element node either doesn't have thelumIsArray
attribute or the value oflumIsArray
attribute is notfalse
.
- Attributes
-
A XML element node attribute named
myAttribute
becomes available using the name$myAttribute
. For example, the given XML node:
myAttribute
available usingmyNode.$myAttribute
.
- Simple element node
-
Simple element node is a node that has the following aspects:
- Has no attributes.
- All of inner nodes are either
CDATA sections
ortext nodes
(comments
are ignored).
- Simple element node with attributes
-
Simple element node with attributes is a node that has the following aspects:
- Has at least one attribute.
- All of inner nodes are either
CDATA sections
ortext nodes
(comments
are ignored).
- Simple element node value
-
The value of a simple element node is the concatenation of all inner
CDATA sections
andtext nodes
. - Complex node
- A complex node is a node that has at least one inner node that is neither a
CDATA section
nor atext node
.
- Parameters:
node
- the node to be transformed inMap
.- Returns:
- a object based on the given node.
- Since:
- 8.1.0
-
getMap
Map<String,Object> getMap(String xpath, Node context)
Selects a node with the given XPath and converts it to aMap
, by usingtoMap(Node)
. If no node could be resolved with the given XPath,null
will be returned.- Parameters:
xpath
- the XPath.context
- the context the given XPath is resolved from.- Returns:
- the found node's map representation or
null
if no node matches the given XPath. - Since:
- 8.2.0
-
getMap
Map<String,Object> getMap(String xpath)
Selects a node with the given XPath and converts it to aMap
, by usingtoMap(Node)
. If no node could be resolved with the given XPath,null
will be returned.- Parameters:
xpath
- the XPath.- Returns:
- the found node's map representation or
null
if no node matches the given XPath. - Since:
- 8.2.0
-
getMaps
List<Map<String,Object>> getMaps(String xpath, Node context)
Selects nodes with the given XPath and converts them to aList
ofMap
, by usingtoMap(Node)
in each of these nodes. If no node could be resolved with the given XPath, an empty list will be returned.- Parameters:
xpath
- the XPath.context
- the context the given XPath is resolved from.- Returns:
- the found nodes' list of maps representation.
- Since:
- 8.2.0
-
getMaps
List<Map<String,Object>> getMaps(String xpath)
Selects nodes with the given XPath and converts them to aList
ofMap
, by usingtoMap(Node)
in each of these nodes. If no node could be resolved with the given XPath, an empty list will be returned.- Parameters:
xpath
- the XPath.- Returns:
- the found nodes' list of maps representation.
- Since:
- 8.2.0
-
-