X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Frecord_conv.c;h=b117340715a8fe7f1d1c6ab48757c2ef1244ca54;hp=1595faf2ceb49a5601bc27cbf8b70bc2652b3c40;hb=b2bc97df294f5da6c93e1119a42536b23afce8ef;hpb=80d0b86c41a5934878cb51657e92060909f320f4 diff --git a/src/record_conv.c b/src/record_conv.c index 1595faf..b117340 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -20,6 +20,7 @@ #include #include #include +#include #if YAZ_HAVE_XML2 #include @@ -331,26 +332,23 @@ static void *construct_select(const xmlNode *ptr, return 0; else { - struct _xmlAttr *attr; NMEM nmem = nmem_create(); struct select_info *info = nmem_malloc(nmem, sizeof(*info)); + const char *attr_str; + const char *xpath = 0; info->nmem = nmem; info->xpath_expr = 0; - for (attr = ptr->properties; attr; attr = attr->next) + attr_str = yaz_xml_get_prop(ptr, "path%s", &xpath); + if (attr_str) { - if (!xmlStrcmp(attr->name, BAD_CAST "path") && - attr->children && attr->children->type == XML_TEXT_NODE) - info->xpath_expr = - nmem_strdup(nmem, (const char *) attr->children->content); - else - { - wrbuf_printf(wr_error, "Bad attribute '%s'" - "Expected xpath.", attr->name); - nmem_destroy(nmem); + wrbuf_printf(wr_error, "Bad attribute '%s'" + "Expected xpath.", attr_str); + nmem_destroy(nmem); return 0; - } } + if (xpath) + info->xpath_expr = nmem_strdup(nmem, xpath); return info; } } @@ -378,19 +376,18 @@ static int convert_select(void *vinfo, WRBUF record, WRBUF wr_error) if (xpathObj) { xmlNodeSetPtr nodes = xpathObj->nodesetval; - wrbuf_rewind(record); if (nodes) { int i; + if (nodes->nodeNr > 0) + wrbuf_rewind(record); for (i = 0; i < nodes->nodeNr; i++) { xmlNode *ptr = nodes->nodeTab[i]; - fprintf(stderr, "xpath result %d type=%d\n", i, - ptr->type); if (ptr->type == XML_ELEMENT_NODE) ptr = ptr->children; - if (ptr->type == XML_TEXT_NODE) - for (; ptr; ptr = ptr->next) + for (; ptr; ptr = ptr->next) + if (ptr->type == XML_TEXT_NODE) wrbuf_puts(record, (const char *) ptr->content); } } @@ -403,8 +400,12 @@ static int convert_select(void *vinfo, WRBUF record, WRBUF wr_error) return ret; } -static void destroy_select(void *info) +static void destroy_select(void *vinfo) { + struct select_info *info = vinfo; + + if (info) + nmem_destroy(info->nmem); }