From b6edc4aff0b7969e251612ec6f61c74bcc7c16f1 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 29 May 2020 13:43:43 +0200 Subject: [PATCH] Added new function (this time for real) --- lib/src/clixon_xml_io.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 45e44d6b..cb4d3982 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -325,6 +325,30 @@ clicon_xml2cbuf(cbuf *cb, return retval; } +/*! Return an xml tree as a pretty-printed malloced string. + * @param[in] x XML tree + * @retval str Malloced pretty-printed string (should be free:d after use) + * @retval NULL Error + */ +char * +clicon_xml2str(cxobj *x) +{ + cbuf *cb; + char *str; + + if ((cb = cbuf_new()) == NULL){ + clicon_err(OE_XML, errno, "cbuf_new"); + return NULL; + } + if (clicon_xml2cbuf(cb, x, 0, 1, -1) < 0) + return NULL; + if ((str = strdup(cbuf_get(cb))) == NULL){ + clicon_err(OE_XML, errno, "strdup"); + return NULL; + } + return str; +} + /*! Print actual xml tree datastructures (not xml), mainly for debugging * @param[in,out] cb Cligen buffer to write to * @param[in] xn Clicon xml tree