41 #include <libxml/xpathInternals.h> 42 #include <libxml/globals.h> 43 #include <libxml/parser.h> 44 #include <libxml/xmlversion.h> 45 #include <libxml/xpath.h> 61 file->
doc = xmlReadFile(filename, NULL, XML_PARSE_NOBLANKS | XML_PARSE_PEDANTIC);
62 if (file->
doc == NULL) {
69 if (file->
name == NULL) {
71 xmlFreeDoc(file->
doc);
86 char filename[] =
"memory";
88 file->
doc = xmlReadMemory(buffer, size, filename, NULL, XML_PARSE_NOBLANKS | XML_PARSE_PEDANTIC);
89 if (file->
doc == NULL) {
96 if (file->
name == NULL) {
98 xmlFreeDoc(file->
doc);
110 if (file->
doc != NULL)
111 xmlFreeDoc(file->
doc);
118 return xmlDocGetRootElement(file->
doc);
122 xmlXPathContext *context = xmlXPathNewContext(file->
doc);
123 if (context == NULL) {
127 xmlXPathObject *result = xmlXPathEval(query, context);
128 xmlXPathFreeContext(context);
129 if (result == NULL) {
133 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
134 xmlXPathFreeObject(result);
139 xmlNodeSet *nodeset = xmlXPathNodeSetMerge(NULL, result->nodesetval);
141 xmlXPathFreeObject(result);
148 xmlXPathFreeNodeSet(nodeset);
152 xmlAttr *prop = xmlHasProp(node, (
const xmlChar*)attribute);
154 return (
const char *)XML_GET_CONTENT(prop->children);
165 if (xmlXPathNodeSetGetLength(nodeset) != 1) {
170 result = xmlXPathNodeSetItem(nodeset, 0);
177 while (node != NULL) {
178 if (node->type == XML_ELEMENT_NODE && xmlStrEqual(node->name, (
const xmlChar*)nodename)) {
182 node = xmlNextElementSibling(node);
210 const char delim[] =
"/";
216 if (nodename == NULL) {
227 level = strtok(str, delim);
228 while (level != NULL) {
232 level = strtok(NULL, delim);
245 if (node == NULL || code == NULL) {
250 xmlChar *valuestr = xmlNodeGetContent(node);
251 if (valuestr == NULL)
255 double res = strtod((
char*)valuestr, &end_ptr);
258 if (end_ptr == (
char*)valuestr) {
271 if (node == NULL || code == NULL) {
277 if (valuestr == NULL)
281 double res = strtod(valuestr, &end_ptr);
284 if (end_ptr == valuestr) {
294 if (codename == NULL) {
321 const char *valuestr;
322 xmlNode *node = NULL;
324 if (codename == NULL) {
329 node = xmlDocGetRootElement(file->
doc);
340 if (valuestr == NULL) {
341 logMsg(
c_logger_Severity_ERROR,
"%s(): Node named '%s/%s' doesn't have attribute '%s' in definition's XML.", __func__, category, codename, attrname);
355 node = xmlDocGetRootElement(file->
doc);
368 if (libname == NULL) {
380 logMsg(
c_logger_Severity_ERROR,
"%s(): Function '%s' load from library '%s' failed with DynUtils error %"PRIi32
".", __func__, codename, libname, ret);
405 #if LIBXML_VERSION < 20904 407 int ret = xmlStrVPrintf(buf, len, (
const xmlChar *)msg, args);
409 int ret = xmlStrVPrintf(buf, len, msg, args);
417 return xmlStrlen(str);
421 return xmlParserVersion;
int c_xml_snprintf(xmlChar *buf, int len, const char *msg,...)
int32_t c_dfload(c_libhandle_t hLib, const char *fcnName, c_fcnhandle_t *funcPtr)
const char * c_xml_getattributevalue(const xmlNode *node, const char *attribute, bool warnEnable)
int32_t c_dlload(const char *libName, c_libhandle_t *libHandle)
void c_xml_freefile(c_xmlfile_t *file)
xmlNode * c_xml_getfirstdescendantelementfromname(xmlNode *node, const char *nodename)
int32_t c_dlclose(c_libhandle_t hLib)
void c_xml_freenodeset(xmlNodeSet *nodeset)
Tools to parse an XML file using libxml.
char * name
the file path (or memory if a memory document passed by c_xml_newfile_from_memory()) ...
int c_xml_strlen(const xmlChar *str)
static c_libhandle_t libHandle
int32_t c_xml_getcodefromnode(const xmlNode *node, double *code)
c_xmlfile_t * c_xml_newfile_from_memory(const char *buffer, int size)
void * c_malloc(size_t size)
xmlNode * c_xml_getnextelementfromname(xmlNode *node, const char *nodename)
Generic wrappers to platform-dependent functions.
c_fcnhandle_t c_xml_getfunctionpointerfromcodename(const c_xmlfile_t *file, const char *codename)
NULL pointer passed as argument.
xmlNode * c_xml_getfirstchildrenelementfromname(xmlNode *node, const char *nodename)
#define INIT_C_LOGGER(fname, mname)
const char * c_xml_parserversion(void)
int32_t c_xml_getcodefromcodename(const c_xmlfile_t *file, const char *__restrict category, const char *__restrict codename, double *code)
const char * c_xml_getattributevaluefromcodename(const c_xmlfile_t *file, const char *__restrict category, const char *__restrict codename, const char *__restrict attrname)
#define c_use_decl_annotations
xmlNode * c_xml_getrootnode(const c_xmlfile_t *file)
void c_xml_parsercleanup(void)
xmlNode * c_getfirstsiblingelementfromname(xmlNode *node, const char *nodename)
xmlNode * c_xml_getfirstnodefromxpathquery(c_xmlfile_t *file, const xmlChar *query)
char * c_strdup(const char *str)
Wrapper to strdup(str), with check for NULL arguments. To be freed with c_free(). ...
xmlNodeSet * c_xml_getnodeset(c_xmlfile_t *file, const xmlChar *query)
c_xmlfile_t * c_xml_newfile(const char *filename)
int32_t c_xml_getcodefromnodechild(const xmlNode *node, double *code)
const char * c_xml_getpath(const c_xmlfile_t *file)