XPATH.FIND

XPATH.FIND performs a query to decoded xml object using xpath-like syntax.

All data in pipelines is represented as JSON-like objects. To work with different formats such as XML and CSV, the Xapix pipeline converts Request, Endpoint and DataSource arguments and parameters into JSON-like representations.

To create suitable tag-children nested structure from scratch, see XPATH.TAGGED.

Function category: XPath

Syntax

XPATH.FIND(arg1, arg2)

Arguments

Description

arg1

Object representation of XML.

arg2

Query to perform.

XPATH.FIND returns either collection of found objects or nil value.

At the moment, only a limited subset of XPath is supported. Only tags path with optional attribute to filter is supported.

/response[foo=bar]/summary-result/message

For example, XML which comes from an XML DataSource as shown below

<response foo="bar">Some Text/<response>

appears in the pipeline as follows:

{"tag": "response",
"attrs": {"foo": "bar"},
"children": ["Some text"]}

See Content-Type codecs for more details on encoding\decoding.

Example

Let's say we receive the following user information:

{
"tag": "request",
"children": [
{
"tag": "cars",
"children": [
{
"tag": "vin",
"children": [
"123"
]
},
{
"tag": "model",
"children": [
"BMW"
]
},
{
"tag": "vin",
"children": [
"456"
]
},
{
"tag": "model",
"children": [
"Audi"
]
},
{
"tag": "vin",
"children": [
"789"
]
},
{
"tag": "model",
"children": [
"Mercedes"
]
}
]
}
]
}
# Perform XPath query on request:
XPATH.FIND(request, '/request/cars/vin')
# Returns {'123','456','789'}