# How to access each leaf-list element individually?

**URL:** <https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871>\
**Category:** Core Engine and APIs\
**Created:** [April 9, 2018, 6:51am UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871 "2018-04-09T06:51:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smswain](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@smswain](https://dmap-community.ductus.global/u/smswain)\
**Post date:** [April 9, 2018, 6:51am UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871/1 "2018-04-09T06:51:26Z")

</div>

Hello,

I want to access each leaf-list element individually for setting and getting as we do for list elements with a path like path/to/list{key}/. I tried to access each leaf-list element with path/to/leaf-list[index], but its saying invalid path. So I want to know whether there is any way to access each leaf-list element individually rather than getting the whole leaf-list as an array.

Also, is there a way to add a single leaf-list element to an existing leaf-list? And delete a single leaf-list element according to value, something like maapi\_delete(path/to/leaf-list{element\_value}) ?

---

<div class="post-metadata">

**Author:** ![waitai](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/waitai/32/436_2.png) [@waitai](https://dmap-community.ductus.global/u/waitai)\
**Post date:** [April 18, 2018, 5:40pm UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871/2 "2018-04-18T17:40:46Z")

</div>

> [@smswain](#):
>
> I tried to access each leaf-list element with path/to/leaf-list[index], but its saying invalid path.

Which ConfD release did you try?

Starting with ConfD 6.5, individual leaf-list elements can be created and deleted instead of setting/deleting the entire leaf-list as a single entity for prior releases.

---

<div class="post-metadata">

**Author:** ![smswain](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@smswain](https://dmap-community.ductus.global/u/smswain)\
**Post date:** [April 23, 2018, 6:52am UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871/3 "2018-04-23T06:52:56Z")

</div>

I was trying with ConfD 6.4. But I have the ConfD 6.5 bin. I will try with that once. I went through the Confd 6.5 User Guide and examples(mostly), but I didn’t find any new information on leaf-list handling. So I would like to ask these questions for clarification(Considering Conf6.5 build).

(1) Will the path to the each leaf-list element be this: path/to/leaf-list[index]?

(2) How to add a single leaf-list element to an existing leaf-list? Will ‘maapi\_set\_elem(path/to/leaf-list, value)’ insert a leaf-list element to the existing leaf-list or will it update the existing leaf-list with the new leaf-list element(i.e., remove previous leaf-list and add a new leaf-list)?

(3) How does the deletion of single leaf-list element work in Confd 6.5? If I do a ‘maapi\_delete(path/to/leaf-list[index])’, then will the confd automatically rearrange the remaining leaf-list or will the removed index be empty?

(4) Is there any way to delete a single leaf-list element according to value, something like ‘maapi\_delete(path/to/leaf-list{element\_value})’ which we do for a list?

Is there any example in the confd 6.5 examples set in which the individual leaf-list elements are set/delete?

Thanks,  
Smruti Ranjan

---

<div class="post-metadata">

**Author:** ![waitai](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/waitai/32/436_2.png) [@waitai](https://dmap-community.ductus.global/u/waitai)\
**Post date:** [April 23, 2018, 9:04pm UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871/4 "2018-04-23T21:04:27Z")

</div>

> [@smswain](#):
>
> went through the Confd 6.5 User Guide and examples(mostly), but I didn’t find any new information on leaf-list handling.

The leaf-list related changes are described in the CHANGES file. A snippet of the description is as follows:

```
  - confd: The internal representation of leaf-lists has changed.
    Leaf-lists now behave similar to lists in terms of operations, i.e.,
    individual elements can now be created and deleted instead of
    setting/deleting the entire leaf-list as a single entity. Attributes
    can be set on individual leaf-list elements.

  ...

```

> [@smswain](#):
>
> (1) Will the path to the each leaf-list element be this: path/to/leaf-list[index]?

You will use the {key\_value} keypath notation to specify what leaf-list element to be added or which leaf-list element to be deleted.

> [@smswain](#):
>
> (2) How to add a single leaf-list element to an existing leaf-list? Will ‘maapi\_set\_elem(path/to/leaf-list, value)’ insert a leaf-list element to the existing leaf-list or will it update the existing leaf-list with the new leaf-list element(i.e., remove previous leaf-list and add a new leaf-list)?

You will use maapi\_create(sock, thandle, path-of-leaf-list{value}) to add an element with value to the end of the leaf-list.

> [@smswain](#):
>
> (3) How does the deletion of single leaf-list element work in Confd 6.5? If I do a ‘maapi\_delete(path/to/leaf-list[index])’, then will the confd automatically rearrange the remaining leaf-list or will the removed index be empty?
> 
> (4) Is there any way to delete a single leaf-list element according to value, something like ‘maapi\_delete(path/to/leaf-list{element\_value})’ which we do for a list?

You will use maapi\_delete(sock, thandle, path-of-leaf-list{value}) to delete an element with value from the leaf-list.

Read the description of the CHANGES file in ConfD 6.5 for more information on the leaf-list related changes.

---

<div class="post-metadata">

**Author:** ![smswain](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@smswain](https://dmap-community.ductus.global/u/smswain)\
**Post date:** [April 24, 2018, 6:49am UTC](https://dmap-community.ductus.global/t/how-to-access-each-leaf-list-element-individually/1871/5 "2018-04-24T06:49:35Z")

</div>

Thanks for the detailed clarification. 🙂 . I forgot to look at the CHANGES file. I will go through it.
