CPS-1221 CPS Xpath search capability Enhancements
- 1 Overview
- 2 Cps Xpath Possibilities
- 2.1 Jira : CPS-1221
- 2.2 1.Using >,< operators
- 2.2.1 Example
- 2.2.2 Description
- 2.3 2.Using Contains function
- 2.3.1 Example
- 2.3.2 Description
- 2.4 3.Using OR & AND functions
- 2.4.1 Example
- 2.4.2 Description
- 2.5 4.Using starts-with/Ends-with function
- 2.5.1 Example
- 2.5.2 Description
- 2.6 5.Using Reqular Expression
- 2.6.1 Example
- 2.6.2 Description
Overview
The wiki discusses upon the enhancement of xpath-capabilities for searching specific elements via CPS-core API and basically to:
provide possibilites to search for specific ranges, operators <>, regex ...
which can be included in future releases.
Cps Xpath Possibilities
Jira : CPS-1221
1.Using >,< operators
Example | Description |
/bookstore/book[@price>800] | Select price nodes with price>800 |
/bookstore/book[@price<1000] | Select 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'] |
|
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” Here, XPath finds those element whose ‘Code’ ending with ‘sid’. |
5.Using Reqular Expression
Example | Description |
/bookstore/book[@title = ^([a-zA-Z{10}\s])] | Suppose ‘title’: ‘Feersum Endjinn’ Here, Xpath finds title attributes accordingly as given in expression |