Table of Contents |
---|
Overview
The wiki discusses upon the enhancement of xpath-capabilities for searching specific elements via CPS-core API and basically to:
- provide possibility to run xpath-searches over multiple anchors and dataspacesprovide possibilites to search for specific ranges, operators <>, regex ...
which can be included in future releases.The second part of this wiki discusses some inconsistencies noticed with the response codes returned by CPS core API's. and how it can be improved.
Cps Xpath Possibilities
Jira : CPS-
...
1221
1.Using >,< operators
Xpath >,< operaters
Example | Description |
/bookstore/book[@price>800] |
Select price nodes with price>800 | |
/bookstore/book[ |
@price<1000] |
selects all the title nodes with a price higher than 800
/bookstore/book[@price>800]/title&limit=2Select price nodes with price<1000 |
NOTE: We can add limit to above examples as a query parameter
2.Using Contains function
...
Example | Description |
//books[contains(@language,'En')] | It is used when the value of any attribute changes dynamically, The contain feature has an ability to find the element with partial text as shown in below XPath example: |
XPath expression partial value |
‘En’ is used in place English |
3.Using OR & AND functions
...
Example | Description |
//books[@title='The Golden compass' or @lang='english'] |
|
|
/ |
/books[@title='The Golden compass' |
and @lang='english'] |
|
/bookstore/book/[@title='The Golden compass' and @lang='english']
- Xpath expression finds values contains barnes and title the lemon table
/bookstore /book[@author contains("Philip Pullman") and @title = "The Golden compass "]
/bookstore /book[@author contains("Iain M
|
4.Using starts-with/Ends-with function
...
Example | Description |
/bookstore/book[starts-with |
(@code,'sid')] |
Code = “sid1” |
Here, XPath finds those element whose ‘Code’ starting with ‘sid’. |
similarly,
...
Example | Description |
/bookstore/book[ends-with(@code,'sid')] |
|
Code = “1-sid” |
Code = “2-sid” |
Code = “3-sid” |
Code = “4-sid” |
Code = “5-sid”
|
/bookstore/book[ends-with(@code,'sid')]
Here, XPath finds those element whose ‘Code’ ending with ‘sid’. |
5.Using Reqular Expression
Xpath Regular Expressions
Example | Description |
/bookstore/book[@title = ^([a-zA-Z{10}\s])] | Suppose ‘title’: ‘Feersum Endjinn’ Here, Xpath finds title attributes accordingly as given in expression |
Search along multiple anchors within a dataspace
Need to create new end point.
For Example,
http://localhost:8883/cps/api/v1/dataspaces/:dataspace-name/nodes?xpath=/bookstore/categories[@code='02'][@title='The Golden Compass']
...