xml_print

This commit is contained in:
Olof Hagsand 2016-04-17 17:52:48 +02:00
parent 55201c9b4a
commit dfa30aa39c
12 changed files with 101 additions and 27 deletions

View file

@ -103,6 +103,7 @@ char *xml_find_body(cxobj *xn, char *name);
int xml_free(cxobj *xn);
int xml_print(FILE *f, cxobj *xn);
int clicon_xml2file(FILE *f, cxobj *xn, int level, int prettyprint);
int clicon_xml2cbuf(cbuf *xf, cxobj *xn, int level, int prettyprint);
int clicon_xml_parse_file(int fd, cxobj **xml_top, char *endtag);

View file

@ -799,6 +799,22 @@ clicon_xml2file(FILE *f,
return retval;
}
/*! Print an XML tree structure to an output stream
*
* Uses clicon_xml2file internally
*
* @param[in] f UNIX output stream
* @param[in] xn clicon xml tree
* @see clicon_xml2cbuf
* @see clicon_xml2file
*/
int
xml_print(FILE *f,
cxobj *xn)
{
return clicon_xml2file(f, xn, 0, 1);
}
#define XML_INDENT 3 /* maybve we should set this programmatically? */
/*! Print an XML tree structure to a clicon buffer

View file

@ -461,6 +461,7 @@ xml2cvec(cxobj *xt,
int ret;
int i = 0;
int len = 0;
char *name;
xc = NULL;
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
@ -472,11 +473,27 @@ xml2cvec(cxobj *xt,
xc = NULL;
/* Go through all children of the xml tree */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL){
if ((ys = yang_find_syntax((yang_node*)yt, xml_name(xc))) == NULL){
clicon_debug(1, "%s: yang sanity problem: %s in xml but not present in yang under %s",
__FUNCTION__, xml_name(xc), yt->ys_argument);
continue;
name = xml_name(xc);
if ((ys = yang_find_syntax((yang_node*)yt, name)) == NULL){
clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
__FUNCTION__, name, yt->ys_argument);
if ((body = xml_body(xc)) != NULL){
cv = cvec_i(cvv, i++);
cv_type_set(cv, CGV_STRING);
cv_name_set(cv, name);
if ((ret = cv_parse1(body, cv, &reason)) < 0){
clicon_err(OE_PLUGIN, errno, "cv_parse");
goto err;
}
if (ret == 0){
clicon_err(OE_PLUGIN, errno, "cv_parse: %s", reason);
if (reason)
free(reason);
goto err;
}
}
}
else
if ((ycv = ys->ys_cv) != NULL){
if ((body = xml_body(xc)) != NULL){
/* XXX: cvec_add uses realloc, can we avoid that? */