Difference between 'x-path' and 'subtree' filter

hi,

Can you please explain with examples in which scenario we need to use ‘x-path’ filter and when to use ‘sub-tree’ filter.

Using a subtree filter, this will select some part of your model and return everything at that point and below it in the tree. RFC 6241 does give a number of examples of subtree filtering. One thing about subtree filtering is that it returns everything, and doesn’t give you additional selection criteria to decide what to return. This is one of the examples in RFC 6241, where everything below “users” in the model will be returned:

 <rpc message-id="101"
      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
   <get-config>
     <source>
       <running/>
     </source>
     <filter type="subtree">
       <top xmlns="http://example.com/schema/1.2/config">
         <users/>
       </top>
     </filter>
   </get-config>
 </rpc>

Now the alternative to subtree filtering is to use an XPath filter. XPath can be used to select what is to be returned. Your XPath filter should return a node-set, that is select items in your model that match the criteria you express in XPath filter. Again using the example in RFC 6241, if you wanted to select the entry in your list of users whose name is ‘fred’, you would use the following XPath filter:

 <rpc message-id="101"
      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
   <get-config>
     <source>
       <running/>
     </source>
     <!-- get the user named fred -->
     <filter xmlns:t="http://example.com/schema/1.2/config"
             type="xpath"
             select="/t:top/t:users/t:user[t:name='fred']"/>
    </get-config>
 </rpc>

As defined in the NETCONF RFC (6241), the subtree filtering feature supports content match nodes which allows only some or all of its sibling nodes to be returned. There is an example in section 6.4.5 of the RFC which shows how the subtree filter can be used to select only a subset of a subtree:

 <rpc message-id="101"
      xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
   <get-config>
     <source>
       <running/>
     </source>
     <filter type="subtree">
       <top xmlns="http://example.com/schema/1.2/config">
         <users>
           <user>
             <name>fred</name>
           </user>
         </users>
       </top>
     </filter>
   </get-config>
 </rpc>

Which one to use depends on your use case. Support of XPath is an optional capability. With subtree filtering, only a small set of filters for inclusion, simple content exact-match, and selection is provided, which allows some useful, but also very limited, selection mechanisms as compared to XPath. Section 6 of the NETCONF RFC (6241) has a very good description on what is supported by subtree filtering along with examples. You can find reference material on XPath from the NETCONF RFC.