SIL and SIL-SA code use the data structure val_value_t to represent YANG data


It may sometimes be useful for debugging or other purposes to save YANG data to an XML file.

  • Use val_dump_value to write XML or other formatted data to the server log file or STDOUT
  • Use xml_wr_file to write XML to a file of your choice


xml_wr_file Definition


/**
* @brief Write the specified value to a FILE in XML format
*
* This is a main module API for high level code.
*
* @param filespec exact path of filename to open
* @param val value for output
* @param attrs top-level attributes to generate
* @param docmode TRUE if XML_DOC output mode should be used\n
*            FALSE if XML output mode should be used
* @param xmlhdr TRUE if <?xml?> directive should be output\n
*            FALSE if not
* @param withns TRUE if xmlns attributes should be used\n
*            FALSE to leave them out
* @param expand_varexpr TRUE if expanding variable expressions\n
*            FALSE if not expanding variable expressions
* @param with_owners TRUE to generate ywx:owner attributes as needed
* @param startindent starting indent point
* @param indent indent amount (0..9 spaces)
* @return status
*/
extern status_t
    xml_wr_file (const xmlChar *filespec,
                 val_value_t *val,
                 xml_attrs_t *attrs,
                 boolean docmode,
                 boolean xmlhdr,
                 boolean withns,
                 boolean expand_varexpr,
                 boolean with_owners,
                 int32 startindent,
                 int32 indent);



xml_wr_file Example


#include <xmlstring.h>
#include "xml_util.h"
#include "xml_wr.h"
#include "val.h"


static status_t write_val (
    const xmlChar *filespec,
    val_value_t *val)
{
    xml_attrs_t attrs;
    xml_init_attrs(&attrs);
    status_t res = xml_wr_file(
        filespec,
        val,
        &attrs,
        false,     // docmode
        true,      // xmlhdr
        true,      // withns
        true,      // expand_varexpr
        false,    // with_owners
        0,          // startindent
        2);        // indent

    xml_clean_attrs(&attrs);
    return res;
}