libyang
libyang copied to clipboard
How to read data using xpath
hi @michalvasko , is there a way to read data using xpath & with libyang API's ?
const struct lys_module *ly_mod = NULL;
LY_ERR lyrc;
struct lyd_node *tree, *node;
struct ly_set *set;
char config_xpath[255]={0};
struct ly_set *set = NULL;
sprintf(config_xpath,"/o-ran-usermgmt:users/user[name='%s']/enabled",session->username);
ly_mod = ly_ctx_get_module_latest(server_opts.ctx, "o-ran-usermgmt");
if (!ly_mod){
VRB(session, "Cannot find module %s", ly_mod->name);
}
else{
VRB(session, "Found module %s", ly_mod->name);
VRB(session, "XPATH is %s", config_xpath);
if(LY_ERR != lyd_find_xpath(server_opts.ctx, config_xpath, &set))
{
node = set->objs[0];
VRB("enable::::::::");
VRB("enable::::%s==============>",lyd_get_value(node));
} else{
VRB("INVALID XPATH to find");
}
::this is crashing
I assume this line is crashing (you should be getting wrong parameter type warnings from your compiler).
if(LY_ERR != lyd_find_xpath(server_opts.ctx, config_xpath, &set))
The first parameter is XPath context node, not libyang context. For absolute XPaths (such as yours) you can use any data node of the data tree.