# Api to get Tagpath from confd\_hkeypath\_t

**URL:** <https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214>\
**Category:** CDB and CDB API\
**Created:** [May 11, 2017, 5:03pm UTC](https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214 "2017-05-11T17:03:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramishet](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ramishet](https://dmap-community.ductus.global/u/ramishet)\
**Post date:** [May 11, 2017, 5:03pm UTC](https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214/1 "2017-05-11T17:03:20Z")

</div>

Hi,

Could you please help me with an api to get the Tagpath from a confd\_hkeypath\_t?

Eg:  
If below is the confd\_hkeypath  
“/hosts/host{buzz}/interfaces/interface{1/1/1}”;

I need the output of the api as below without the keys  
“/hosts/host/interfaces/interface”;

Thanks in advance.  
Ramishet

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [May 12, 2017, 9:37am UTC](https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214/2 "2017-05-12T09:37:58Z")

</div>

Hello,

i believe there is no explicit API/procedure to do it “automatically”.

You can easily get it by iterating the input keypath, and copying only the C\_XMLTAG elements to the output…

pseudo code:

```
int output_len = 0;
for (i = 0; i < input->len; i++) {
    if (C_XMLTAG == input->v[i][0].type) {
        confd_value_dup_to(&input->v[i][0], &output->v[output_len++][0]);
    }
}
output->len = output_len;
```

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [May 12, 2017, 9:44am UTC](https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214/3 "2017-05-12T09:44:07Z")

</div>

in addition, whenever working with artificial keypaths created in custom code, for safety reasons it might be a good idea to set/add a border values not occupied by keypath “tags” to `C_NOEXISTS`… (e.g. setting `CONFD_SET_NOEXISTS(&output->v[output->len][0])` etc.

(depending on what you do with the output keypath, for the output key to be a “proper one” that can be safely passed to e.g. `confd_free_hkeypath()`, `confd_hkeypath_dup()`, etc.)

---

<div class="post-metadata">

**Author:** ![ramishet](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ramishet](https://dmap-community.ductus.global/u/ramishet)\
**Post date:** [May 18, 2017, 5:29am UTC](https://dmap-community.ductus.global/t/api-to-get-tagpath-from-confd-hkeypath-t/1214/4 "2017-05-18T05:29:39Z")

</div>

Thanks a lot Joseph for your quick support
