Read an XML file into memory. More...
#include <xml_utils.h>
Go to the source code of this file.
Functions | |
xmlConfig_t * | xml_load_config (char *filename) |
Read an XML file into memory. |
Read an XML file into memory.
Definition in file xml_load_config.c.
xmlConfig_t* xml_load_config | ( | char * | filename | ) |
Read an XML file into memory.
[in] | filename | Input XML filename |
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 }