#edit-config-xpath capability
#edit-config-xpath capabilities modifies the behavior of the edit-config operation. It allows the use of XPath to address the nodes on which an operation will be done. This capability adds new attributes to the config element:
- type: can be one of "subtree" or "xpath". "subtree" addresses the edit-config as specified in the Netconf draft. If the "type" attribute is set to "subtree", edit-config works in the same way as specified in the draft. If the "type" attribute is set to "xpath", the "operation" and "sel" attributes are required,
- operation: can be one of "create", "delete" or "replace",
- sel: an xpath expression that selects a set of nodes in the specified target configuration.
Creating a new XML element
This operation appends the given node as a child of all the nodes selected by the "sel" XPath expression. In the example, it will create a user under the users element(s).
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <edit-config> <target> <running/> </target> <config type="xpath" xmlns:rr="my:own:namespace:root:elements" xmlns:uu="my:own:namespace:users" operation="create" sel="/rr:top/uu:users"> <user xmlns="my:own:namespace:users"> <name>Alice</name> <login>alicefoo</login> </user> </config> </edit-config> </rpc> |
Deleting an XML element
The "delete" operation deletes all the nodes selected by the "sel" XPath expression. When the operation attribute is set to "delete", "config" must not have children. In the example, it will delete all the users.
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <edit-config> <target> <running/> </target> <config type="xpath" xmlns:rr="my:own:namespace:root:elements" xmlns:uu="my:own:namespace:users" operation="delete" sel="/rr:top/uu:users/uu:user"> </config> </edit-config> </rpc> |
Replacing an existing XML element
The "replace" operation replaces all the selected nodes with the given node. In the example, it replace the user which name is 'Alice' with a new user having the same name.
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <edit-config> <target> <running/> </target> <config type="xpath" xmlns:rr="my:own:namespace:root:elements" xmlns:uu="my:own:namespace:users" operation="replace" sel="/rr:top/uu:users/uu:user[uu:name='Alice']"> <user xmlns="my:own:namespace:users"> <name>Alice</name> <login>alicefoo</login> <building>a2</building> <room>100</room> </user> </config> </edit-config> </rpc> |