lum_xpath is an object designed to provide various methods that facilitate the retrieval of data from the context (XML) of the interface whose style is being generated, through the use of XPath.
Returned Type |
Method |
Description |
String |
valueOf(String xpath, Node context) |
Returns a string representing the value of the node in the xpath of the given context. |
Node |
selectSingleNode(String xpath) |
Returns a single element with the XPath in the given context. If the context is not provided, the document (lum_document) will be used. When more than one element is found, only the first will be returned. If no element is found, null is returned. |
Node |
selectSingleNode(String xpath, Node context) |
|
List<Node> |
selectNodes(String xpath) |
Returns a list of all elements with the XPath in the given context. If the context is not provided, the document (lum_document) will be used. If no element is found, an empty list will be returned. |
List<Node> |
selectNodes(String xpath, Node context) |
|
Map<String, Object> |
toMap(Node node) |
Returns a map representing the given node. For more information on the structure of the map and its conversion rules, see the page IXPath.toMap. |
Map<String, Object> |
getMap(String xpath) |
Searches for a node with the given context and converts it into a map using the toMap method. If the context is not provided, the document (lum_document) will be used. If no node is found with the given context, null is returned. |
Map<String, Object> |
getMap(String xpath, Node context) |
|
List<Map<String, Object>> |
getMaps(String xpath) |
Searches for nodes with the given context and converts them into a list of maps using the toMap method on each found node. If the context is not provided, the document (lum_document) will be used. If no node is found with the given context, an empty list will be returned. |
List<Map<String, Object>> |
getMaps(String xpath, Node context) |
Below are a series of usage examples for each method:
Usage examples of the lum_xpath.valueOf method:
XML |
JavaScript |
Example 1: Simple node value |
|
Code
|
|
Return The above code would return the string "News". |
|
Example 2: Node value with children |
|
Code
|
|
Return The above code would return the string "News Quick List". Note that the values of the children were concatenated in the return. |
Usage examples of the lum_xpath.selectSingleNode method
XML |
JavaScript |
Example 1: Fetching a node without passing context |
|
Code
|
|
Return The above code would return the data node, which could be used in the valueOf example: |
|
Example 2:Fetching a node specifying a context |
|
Code |
|
Return The above code would return the patterns node, which can be used in the valueOf example: |
Usage examples of the lum_xpath.selectNodes method
XML |
JavaScript |
Example 1: Fetching a list of nodes |
|
Code |
|
Return The above code fetches a list of all "row" nodes with the given XPath and creates a list of links using the title and href values of them |
Usage examples of the lum_xpath.toMap method
XML |
JavaScript |
Example 1: Using a node's map |
|
Code |
|
Return The above code fetches a list of all "row" nodes with the given XPath and for each node creates a map to generate a list of links using the title and href. |