ConfD User Community

Any MAAPI function to get data with XPATH?

I want to get the data for XPATH such as “components//state”
Is there any maapi API to get the data of this XPATH?


You can use maapi_save_config() function

int maapi_save_config(int sock, int thandle, int flags, const char *fmtpath, …);
This function can be used to save the entire config (or a subset thereof) in different formats.

int id, streamsock;
struct sockaddr_in addr;
id = maapi_save_config (maapi_fd, txn_handler, MAAPI_CONFIG_XML_PRETTY,"/components/state");
addr.sin_addr.s_addr = inet_addr("<confd_ip_addr>");
addr.sin_family = AF_INET;
addr.sin_port = htons(CONFD_PORT);

       streamsock = socket(PF_INET, SOCK_STREAM, 0);
       confd_stream_connect(streamsock, (struct sockaddr*)&addr, sizeof(struct sockaddr_in), id, 0);

      while (( iRetVal = read(streamsock, buf, BUFSIZ)) > 0) {

 maapi_save_config_result(maapi_fd, id)

Finally config data will be present in buf. You can refer confd_lib_maapi manual page for more details

As @BharatAkiwate writes, maapi_save_config can do that (don’t forget to add MAAPI_CONFIG_XPATH flag); but it might not be convenient if you expect very large data, in which case either maapi_xpath_eval or the set of functions maapi_query_* might do better job.

@mvf, @BharatAkiwate, thank you, I tried with maapi_query_*, and could get data sucessfully.

Do I have a method to filter rw or ro attributes via select[ ]?
For example, I have xpath “components//state” and “component//config” , I want to get all configure data and state data. Is there any examples for filter?

I’m not sure I understand what you ask for. If you know the data model, you can obviously fill the select array with the leaf names you want to retrieve; even if you need your query to be more generic, you can use the runtime schema data and filter / filter out all writable nodes and fill the array accordingly. But there is no single XPath expression that would tell confd to return exactly writable nodes.