Replies: 3 comments 1 reply
-
You cannot do this, libyang enforces and then always expects nodes to follow their schema ordering and for system-ordered (leaf-)lists, even the relative order of all the instances is strict. So my first question would be why do you want to use some other node ordering. |
Beta Was this translation helpful? Give feedback.
-
I am ok with default libyang ordering. No problems with that. I am just trying to achieve swaping of particular subtree with a new one (the root nodes of old and new subtrees are always using the same schema) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint about the libyang native ordering mechanism. I though that it is always the putting it as last. Now it make sense. I was also not aware about So all that is left is that I just need to handle a special case when I am replacing subtree, within Thanks for the hints |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to perform replacement of particular subtree within the data tree with a brand new one while I wish to preserve node ordering regardless of associated schema. As this is not possible natively (there is no
lyd_change_inner()
norlyd_swap_node()
API), my workaround consist of the following steps:The problematic is the 2. step. It requires to have full control of node positioning, which is not allowed:
lyd_insert_after()
orlyd_insert_before()
is acceptable only when associated schema is list/leaf-list withordered-by user;
lyd_insert_sibling()
)lyd_new_term()
)Alternative approach that I also consider was like this:
I am not sure if this will work or not correctly as there is also the node hashing part, for which I have no clue how to should work, but I guess something needs to be done and as this is not able to be done via libyang public APIs.... So it would mean I would need to create a libyang patch first...
Another alternative was to swap the references of
prev
&next
of old and new subtrees, and also change thechild
reference of parent in case old subtree is first child. But again the question about the hashing pops up.I was also considering creating a diff between those two subtrees and then apply diff or original subtree, but it seems to be relatively expensive operation as it involves creation of third subtree...
So do you have some better ideas how to achieve the needed result? Thanks
Beta Was this translation helpful? Give feedback.
All reactions