Open ahassany opened 1 month ago
I think that XPath evaluation doesn't cross anyxml
or anydata
boundaries. In our code, if the struct lyd_node_any::value_type
is LYD_ANYDATA_DATATREE
, we access its .value.tree
and that one effectively becomes a root node, see this unit test in our C++ bindings. I see that we have no tests for XPath evaluation "below" that node, though.
OTOH, when I read the docs, I see that lyd_find_path
ignores "opaque" nodes, while lyd_find_xpath
is said to support them...
Thank you for the quick response, and thank you for the C++ reference I need to spend more time with it as I'm not very familiar with the C++ bindings.
for lyd_find_xpath
I think it's a bug since the doc states that it crosses the opaque while the implementation doesn't work as expected.
You are considering any
nodes as opaque
nodes, they are not the same. When documentation mentions opaque
nodes, it refers to opaque nodes that are part of the data tree, not those part of any
nodes. The content of any
nodes is not directly traversed/considered by any libyang functions.
We can discuss changing this but there are some problems bound to arise. For example, paths that cross module top-level nodes inside the path are supported for schema-mount
nodes, which could then be confused with paths referencing nodes in any
nodes.
Thank you Michal for the explanation, however, The content of any nodes is not directly traversed/considered by any libyang functions.
is a strong statement, at least the print statements traverses the any nodes. I only understand schema-mount
on high-level but not sure how it's implemented in libyang.
So, I'm trying to dig a bit in the code just to understand better what's going, I noticed that in line https://github.com/CESNET/libyang/blob/master/src/tree_data_new.c#L289 the parent for any
tree is set to NULL
.. I hope I'm looking at the right place.
So my question, why is the parent of any is null? not the any data node? or it's parent?
at least the print statements traverses the any nodes.
Fair enough, printer does traverse these nodes.
why is the parent of any is null?
Because the contents of any
nodes are treated as a separate data tree. They have no parent
and no node has child
set to this data tree. You need to manually go into the any
node data tree.
Is there a fundamental reason for that? or just implementation details? When parsing YANG data, I would assume yang will have one data tree not many.
The main reason is that a standard YANG data should begin with instances of top-level schema nodes and then include any descendants as children. In this case there would, again, be top-level nodes, which is confusing and may even cause ambiguities when referencing these nodes.
Also, this rule is broken because of schema-mount
but it could not be implemented any other way.
I using latest libyang from master to query YANG data trees with XPath, but I noticed XPath evaluation is skipping the anydata nodes. Is that by design or there's a bug somewhere?
To clarify my issue. In the following example, I'm trying to use XPath over a yang push notification. What comes after is defined as
anydata
in the schema. I can query everything for the following xpath/ietf-yang-push:push-change-update/ietf-yang-push:datastore-changes/ietf-yang-push:yang-patch/ietf-yang-push:edit/ietf-yang-push:value
but it returns nothing for this xpath/ietf-yang-push:push-change-update/ietf-yang-push:datastore-changes/ietf-yang-push:yang-patch/ietf-yang-push:edit/ietf-yang-push:value/ietf-interfaces:interfaces
The output is: