I am working with NETCONF and Sysrepo. When a change is made in the sysrepo managed configuration, it gives a call back so that the corresponding change can be effected in the underlying hardware. The call back has an xpath
parameter which gives the exact location in the yang model where the data has been changed. Some examples are as follows:
/ietf-interfaces:interfaces/interface[name='mgmt7']/ietf-ip:ipv4/mtu
/ietf-interfaces:interfaces/interface[name='mgmt7']/ietf-ip:ipv4/address[ip='192.168.1.15']/prefix-length
/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-routing:static'][name='static']/static-routes/ietf-ipv4-unicast-routing:ipv4/route[destination-prefix='17.0.0.0/8']/destination-prefix
Now to processes this I have a requirement to parse this and split into components. For example the first item may be split into a json format as follows:
{
"class": "ietf-interfaces",
"path": "interfaces/interface",
"item": "mgmt7",
"subtree": {
"class": "ietf-ip",
"path": "ipv4/mtu"
}
}
I have searched but could not find any library which can parse or split an xpath
. Most libraries are used to use an xpath
to locate a data in an xml file.
What would be a good approach to parse the xpath
into some thing like I have described above?
Thanks!