If the val_value_t node represents a leaf or a leaf-list node and its value can be converted to a string format then the following API can be used to malloc a buffer that holds an xmlChar string:



/********************************************************************
* FUNCTION val_make_sprintf_string
*
* Malloc a buffer and then sprintf the xmlChar string
* NETCONF representation of a simple value
*
* INPUTS:
*    val == value to print
*
* RETURNS:
*   malloced buffer with string represetation of the
*     'val' value node
*   NULL if some error
*********************************************************************/
xmlChar *
    val_make_sprintf_string (const val_value_t *val)


As an example this API can be used as follows:


/********************************************************************
* FUNCTION print_children
*
* Dump children values
*
********************************************************************/
static void print_children (val_value_t *val,
                            const char *which)
{
    val_value_t *child = NULL;

    log_debug("\n    %s %s P:[%p] :",
              which,
              val ? VAL_NAME(val) : NCX_EL_NULL,
              val);
    if (val) {
        val_dump_value(val, 5, DBG4);

        strval = val_get_first_child(val);

        while (child) {

            if (VAL_TYPE(child) && typ_is_simple(VAL_TYPE(child))) {
                xmlChar *valstr = val_make_sprintf_string(child);
                if (valstr == NULL) {
                    res = ERR_INTERNAL_MEM;
                    return;
                }

                log_debug4("\nchild:   %s:'%s'",
                          VAL_NAME(child),
                          valstr);

                m__free(valstr);
            }

            child = val_get_next_child(child);
        }
    }
} /* print_children */