xml_load_config.c File Reference

Read an XML file into memory. More...

#include <xml_utils.h>
Include dependency graph for xml_load_config.c:

Go to the source code of this file.

Functions

xmlConfig_txml_load_config (char *filename)
 Read an XML file into memory.

Detailed Description

Read an XML file into memory.

Definition in file xml_load_config.c.


Function Documentation

xmlConfig_t* xml_load_config ( char *  filename  ) 

Read an XML file into memory.

Parameters:
[in] filename Input XML filename
Returns:
XML information about DOM and XPath

Definition at line 58 of file xml_load_config.c.

References alloc_error(), xmlConfig_t::ctxt, xmlConfig_t::doc, xmlConfig_t::file, xmlConfig_t::root, and xml_free_config().

Referenced by load_conf().

00058                                 {
00065   xmlConfig_t *conf = NULL;
00066 
00067   conf = (void *) malloc(sizeof(xmlConfig_t));
00068   if (conf == NULL) alloc_error(__FILE__, __LINE__);
00069  
00070   /* Copy filename */
00071   conf->file = strdup(filename);
00072   if (conf->file == NULL) alloc_error(__FILE__, __LINE__);
00073 
00074   (void) xmlInitParser();
00075 
00076   /* Create DOM tree from XML file */
00077   (void) xmlKeepBlanksDefault(0);
00078   conf->doc = xmlParseFile(conf->file);
00079   if (conf->doc == NULL) {
00080     (void) xml_free_config(conf);
00081     (void) xmlCleanupParser();
00082     return NULL;
00083   }
00084 
00085   /* Get root */
00086   conf->root = xmlDocGetRootElement(conf->doc);
00087   if (conf->root != NULL && xmlStrcasecmp(conf->root->name, (unsigned const char *) "configuration")) {
00088     (void) xml_free_config(conf);
00089     (void) xmlCleanupParser();
00090     return NULL;
00091   }
00092 
00093   /* Initialize XPath environment */
00094   (void) xmlXPathInit();
00095 
00096   /* Create XPath Context */
00097   conf->ctxt = xmlXPathNewContext(conf->doc);
00098   if (conf->ctxt == NULL) {
00099     (void) xml_free_config(conf);
00100     (void) xmlCleanupParser();
00101     return NULL;
00102   }
00103 
00104   return conf;
00105 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1