Parsing RPC reply difference from libyang 1 to libyang 2
Hi,
I am facing an issue regarding how to parse a simple RPC reply string. Namely, the string literal I am trying to parse is <ok/> (a basic rpc-reply).
I am updating some code that was previously written using libyang 1, and this string was previously parsed using lyxml_parse_mem without problems. Since the lyxml_* API is removed in libyang 2 I have tried parsing this string using lyd_parse_data, lyd_parse_data_mem and lyd_parse_op. However, I get errors regarding a missing XML namespace (rightfully so, since there is no xmlns tag in the string) and If I try to add an XML namespace the error message simply says that the node I am trying to parse is missing from the corresponding module. All of this is done with the same context as before, which was working fine using lyxml_parse_mem.
My question is whether there is a way to parse a string like this one (or even a more complex rpc-reply) with libyang to be able to traverse the XML tree (possibly in the form of lyd_nodes)? I have tried using the LYD_PARSE_OPAQ parsing option, but the lyd_node being output from the several parsing methods is NULL, so I can't cast them to lyd_node_opaq.
Could I get some guidance regarding whether if I can achieve the same functionality using libyang 2?
Thanks in advance!
I have tried parsing this string using lyd_parse_data, lyd_parse_data_mem and lyd_parse_op.
lyd_parse_op() is the function you want to use with LYD_TYPE_REPLY_NETCONF for parsing the whole NETCONF reply meaning
<rpc-reply ....>
<ok/>
</rpc-reply>
That is the preferred way libyang v2 is parsing NETCONF replies.
Parsing only the nested data of rpc-reply is not directly supported but should work with lyd_parse_data*() and the LYD_PARSE_OPAQ option.