1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. Copyright (C) 2023 Nordix Foundation
5 .. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING
18 In CPS , Xpath is a parameter used in several APIs, which allows us to retrieve JSON and XML data efficiently.
19 The XPath syntax provides us with the ability to navigate through the hierarchical structure of data used in CPS easily via specification of node names, values ,attributes etc.
28 namespace "org:onap:ccsdk:sample";
32 revision "2020-09-15" {
88 **Note.** 'categories' is a Yang List and 'code' is its key leaf. All other data nodes are Yang Containers. 'label' and 'edition' are both leaf-lists.
98 "bookstore-name": "Chapters",
108 "title": "2001: A Space Odyssey",
110 "label": ["sale", "classic"],
111 "edition": ["1968", "2018"]
116 "label": ["classic"],
142 - Xpaths uses 'nodes' to navigate through the data.
143 - Nodes typically used in CPS:
146 - leaf (CPS does not support addressing leaf nodes using XPath syntax)
147 - JSON data and XML data are node trees
148 - the 'root node' contains all the configuration data nodes that exist at the top-level in all modules, serving as their parent node.
153 - Every node has a parent, not every node has a children
154 - Ancestor: a node's parent, parent's parent , parent's parent's parents …
155 - In the given sample model and data, the top data node 'shops' is the ancestor of every other node
156 - Descendants: a node's children, children's children, children's children's children
157 - In the given sample model and data, the list node 'books' is a descendant of the container node 'books'
159 Supported XPath syntax in CPS
160 =============================
165 - ``/``: Selects from the root node
166 - **Note:** CPS uses absolute location path which means that XPath expression expected in CPS must start with / followed by the nodes leading to the node being selected.
167 - ``@``: Selects attributes
168 - **Note:** Providing the attribute value can be enclosed in quotations i.e. ``[@code=1]`` will provide same result as ``[@code='1']``
175 - Selected node(s) without descendants
178 - Selects the root node
179 - .. code-block:: json
183 "book-store:shops": {}
187 - Selects the bookstore container node
188 - .. code-block:: json
192 "book-store:bookstore": {
194 "bookstore-name": "Chapters"
198 * - /shops/bookstore/categories[@code='1']
199 - Selects 'categories' list node in 'bookstore' container that contains the key attribute 'code=1'
200 - .. code-block:: json
204 "book-store:categories": {
211 * - /shops/bookstore/categories[@code='1']/books
212 - Selects the 'books' container node in 'categories' list node in 'bookstore' container that contains the key attribute 'code=1'
213 - .. code-block:: json
217 "book-store:books": {}