In this article the following simple YANG data model will be used for illustration:
module example {
namespace "http://www.yumaworks.com/ns/example";
prefix example;
revision "2019-01-01";
container cont1 {
list list1 {
key "name";
leaf name {
type string;
}
}
}
}Now, for example, when we have a val_value structure that represent container "cont1" and all its children, we can use the following loop to iterate through its children list:
{
/* this is the parent val_value that represents "cont1" container */
val_value_t *parentval;
/* this is the first list in the Queue */
val_value_t *chval = val_get_first_child(parentval);
if (!chval) {
// there is no children
}
/* now we can iterate through all the list entries */
for (; chval != NULL; chval = val_get_next_child(chval)) {
val_value_t *key_val =
val_find_child(chval,
(const xmlChar *)"example", // module name
(const xmlChar *)"name"); // child leaf name to find
if (!key_val) {
/* there is no key; should not happen; list should always have keys */
}
}
}