The XPath capability indicates that a device can use XPath expressions as filter criteria in the <filter> element, and the <get> and <get-config> operations can query specified data through an XPath.
XPath — XML Path Language — uses path expressions for the addressing of parts of an XML file. The XPath syntax is similar to the file path in the file management system.
If an XPath expression is used as a filter criterion, the value of the type attribute in the <filter> element is xpath, and the value of the select attribute (which must exist) 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 such operations as notifications, full synchronization, incremental synchronization, or copy-config.
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 /acl:acl/acl:groups/acl:group 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:acl="urn:huawei:yang:huawei-acl" select="/acl:acl/acl:groups/acl:group[acl:identity='2000']"/> </get-config> </rpc>
<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>
Use two or more XPaths in the OR relationship as filter criteria to query information about the same node in all expressions.
For example, query information about the same node in the /nacm/rule-list/group and /nacm/rule-list/rule XPaths of the <candidate/> configuration database.
<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 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>
Use the /* symbol as a filter criterion to query information about all nodes in the specified XPath (before the * symbol).
For example, you can query information about all nodes in the /nacm XPath of the <candidate/> configuration database.
<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 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>
For example, either of the following expressions is used to query the data of nodes 1 to 100 on the list node interface.
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() >= 1 and position() <= 100] "
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() <= 100 and position() >= 1] "
For example, the following expression is used to query the data of the first node on the list node interface.
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() >= 1 and position() <= 1] "
For example, the first of the following two expressions is used to query the data of node 100 and all the subsequent nodes on the list node interface, and the second expression is used to query the data of nodes 1 to 200 on the list node interface.
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() >= 100] "
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() <= 200] "
For example, the following expression contains two filter criteria, indicating that the GE port data of nodes 1 to 100 is queried.
select="/ifm:ifm/ifm:interfaces/ifm:interface[ifm:type='gigabitethernet'][position() >= 1 and position()<= 100]"
For example:
select="/ifm:ifm/ifm:interfaces/ifm:interface[position() >= 1 and position() <= 100] "
In the preceding expression, the node interface is a list node, and the expression [position() >= 1 and position() <= 100] is not followed by another node.
For example:
select="/t:ifm/t:interfaces/t:interface[position() >= 1 and position()<= 100]"
select="/l:ifm/l:interfaces/l:interface[position() >= 101 and position()<= 200]"
During packet delivery, the greater-than sign (>) and less-than sign (<) in the position() expression must be represented by the escape characters > and <.
For example, query information about the first and second NACM authentication user groups in the <running/> configuration database.
<?xml version="1.0" encoding="utf-8"?> <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="827"> <get-config> <source> <running/> </source> <filter xmlns:t="urn:ietf:params:xml:ns:yang:ietf-netconf-acm" type="xpath" select="/t:nacm/t:groups/t:group[position()>=1 and position()<=2]"/> </get-config> </rpc>
<?xml version="1.0" encoding="utf-8"?> <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"> <groups> <group> <name>1</name> <user-name>test1</user-name> <user-name>test2</user-name> <user-name>test3</user-name> <user-name>test4</user-name> </group> <group> <name>2</name> <user-name>test1</user-name> <user-name>test2</user-name> <user-name>test3</user-name> </group> </groups> </nacm> </data>