XPath
This capability indicates that the device can use XPath expressions in the <filter> element as query conditions. The <get> and <get-config> operations can query specified data through an XPath.
XPath is an XML Path language that uses path expressions for the addressing of parts of an XML file. Like the file path in the file management system, the most basic XPath syntax is similar to the file path in the file management system.
- An XPath can only be a basic absolute path. Steps are separated using slashes (/), such as /acl/aclGroups/aclGroup.
- Only predicates in the [node name='value'] format (for example, [genre='Computer']) are supported. There can be multiple predicates in an AND relationship.
- XPath supports multiple namespaces that are separated using colons.
If an XPath expression is used as a filter criterion, the value of the "type" attribute in the <filter> element is "xpath" and the "select" attribute must exist. The value of the "select" attribute is the XPath expression.
<filter type="xpath" xmlns:acl="urn:huawei:yang:huawei-acl" select="/acl:acl/acl:groups/acl:group[acl:identity='2000']"/>
XPath expressions cannot be used as filter criteria for notifications, full synchronization, incremental synchronization, and copy-config operations.
XPath expressions support the following operations:
Use the specified XPath as a filter criterion to query information about all nodes in the XPath.
For example, query information about all nodes in the /netconf/authorization/taskGroupRules/taskGroupRule XPath of the <running/> configuration database.
RPC request
<?xml version="1.0" encoding="utf-8"?> <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="19"> <get-config> <source> <running/> </source> <filter xmlns:acl="urn:huawei:yang:huawei-acl" type="xpath" select="/acl:acl/acl:groups/acl:group"/> </get-config> </rpc>
RPC reply
<?xml version="1.0" encoding="utf-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="6"> <data> <acl xmlns="urn:huawei:yang:huawei-acl"> <groups> <group> <identity>2000</identity> <type>basic</type> <match-order>config</match-order> <step>5</step> </group> </groups> </acl> </data> </rpc-reply>
Use the value of a node in the specified XPath as a filter criterion to query information about the node that matches this value in the XPath.
For example, query information about the node for which "identity" is set to 2000 in the/acl:acl/acl:groups/acl:group XPath of the <running/> configuration database.
RPC request
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"> <get-config> <source> <running/> </source> <filter type="xpath" xmlns:t="urn:huawei:yang:huawei-acl" select="/acl:acl/acl:groups/acl:group[acl:identity='2000']"/> </get-config> </rpc>
RPC reply
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"> <data> <acl xmlns="urn:huawei:yang:huawei-acl"> <groups> <group> <identity>2000</identity> <type>basic</type> <match-order>config</match-order> <step>5</step> </group> </groups> </acl> </data> </rpc-reply>
In an XPath expression, the bit-is-set function is used as a query condition to query the node information that meets the bit-is-set function requirements in the XPath.
select="/t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statment-list[bit-is-set(t:test-bits, 'create')]"
In the preceding information, bit-is-set(t:test-bits, 'create') is the bit-is-set function expression. test-bits is a node name defined in the YANG file, and create is the value assigned to the test-bits node. If the value exists in the YANG file, true is returned for the bit-is-set function; otherwise, false is returned. If true is returned for the bit-is-set function, the system queries the node information that meets the bit-is-set function requirements in the specified XPath. If false is returned for the bit-is-set function, the RPC reply carries error information.
If the YANG file defines test-bits as follows:
leaf test-bits { type bits { bit create; bit read; bit update; bit delete; } }
For example, query information about the test-bits node for which value delete is assigned in the /t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statement-list XPath of the <running/> configuration database.
RPC request
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <source> <running/> </source> <filter xmlns:t="http://www.huawei.com/netconf/vrp/huawei-yang-1-1-test" type="xpath" select="/t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statment-list[bit-is-set(t:test-bits, 'delete')]"/> </get-config> </rpc>
RPC reply
<rpc-reply message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <huawei-yang-1-1-test xmlns="http://www.huawei.com/netconf/vrp/huawei-yang-1-1-test"> <rfc6020-statements> <rfc6020-statment-list> <name>ruleext_3</name> <test-bits>delete</test-bits> </rfc6020-statment-list> </rfc6020-statements> </huawei-yang-1-1-test> </data> </rpc-reply>
For example, query information about the test-bits node for which value aaa is assigned in the /t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statment-list XPath of the <running/> configuration database.
RPC request
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <source> <running/> </source> <filter xmlns:t="http://www.huawei.com/netconf/vrp/huawei-yang-1-1-test" type="xpath" select="/t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statment-list[bit-is-set(t:test-bits, 'aaa')]"/> </get-config> </rpc>
RPC reply
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="12"> <rpc-error> <error-type>protocol</error-type> <error-tag>bad-element</error-tag> <error-severity>error</error-severity> <error-path xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:t="http://www.huawei.com/netconf/vrp/huawei-yang-1-1-test"> /nc:rpc/nc:get-config/nc:filter/t:huawei-yang-1-1-test/t:rfc6020-statements/t:rfc6020-statment-list/t:test-bits </error-path> <error-message xml:lang="en">Invalid value "aaa" in "test-bits" element.</error-message> <error-info> <bad-element>test-bits</bad-element> </error-info> </rpc-error> </rpc-reply>
Use two or more XPaths in the AND relationship as filter criteria to query the same node information contained in all expressions.
For example, query the same node information contained in the /nacm/rule-list/group and /nacm/rule-list/rule XPaths of the <candidate/> configuration database.
- RPC request
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get-config> <source> <candidate/> </source> <filter type="xpath" select="/t:nacm/t:rule-list/t:group | /t:nacm/t:rule-list/t:rule" xmlns:t="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"/> </get-config> </rpc>
- RPC reply
<rpc-reply message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <data> <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"> <rule-list> <name>list1</name> <group>group1</group> <rule> <name>rule11</name> <module-name>*</module-name> <access-operations>create read update delete</access-operations> <action>permit</action> <rpc-name>commit</rpc-name> </rule> <rule> <name>rule12</name> <module-name>*</module-name> <access-operations>read</access-operations> <action>deny</action> <rpc-name>edit-config</rpc-name> </rule> </rule-list> <rule-list> <name>list2</name> <group>group2</group> <rule> <name>rule21</name> <module-name>*</module-name> <access-operations>create read update delete</access-operations> <action>permit</action> <rpc-name>commit</rpc-name> </rule> </rule-list> </nacm> </data> </rpc-reply>
- RPC request
Use the "/*" symbol to query all node information before the asterisk (*) in an XPath.
For example, query all node information in the /nacm XPath of the <candidate/> configuration database.
- RPC request
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get-config> <source> <candidate/> </source> <filter type="xpath" select="/t:nacm/*" xmlns:t="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"/> </get-config> </rpc>
- RPC reply
<rpc-reply message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <data> <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"> <enable-nacm>false</enable-nacm> <read-default>deny</read-default> <write-default>deny</write-default> <exec-default>deny</exec-default> <groups> <group> <name>group1</name> <user-name>puneeth1</user-name> <user-name>puneeth2</user-name> <user-name>puneeth3</user-name> </group> <group> <name>group2</name> <user-name>puneeth1</user-name> <user-name>puneeth2</user-name> <user-name>puneeth3</user-name> </group> </groups> <rule-list> <name>list1</name> <group>group1</group> <rule> <name>rule11</name> <module-name>*</module-name> <access-operations>create read update delete</access-operations> <action>permit</action> <rpc-name>commit</rpc-name> </rule> <rule> <name>rule12</name> <module-name>*</module-name> <access-operations>read</access-operations> <action>deny</action> <rpc-name>edit-config</rpc-name> </rule> </rule-list> </nacm> </data> </rpc-reply>
- RPC request