From 9fd5dd76e0bb2c992adc7723627f0e301bf00154 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Thu, 8 Mar 2007 17:19:12 +0000 Subject: [PATCH] changed and parser such that the following conditions actually work: 1) no element at all 2) empty element 3) element starting with an instruction (that is, and/or not mandatory any more. Needed to make new define DOM_INPUT_DOM besides DOM_INPUT_MARC and DOM_INPUT_XMLREADER Still missing detection of or after all nodes. And more important: when finding errors here, it's kind of lam just to emit an warning, one should stop processing! --- index/mod_dom.c | 41 ++++++++++++++++++++++++++++++++--------- test/xslt/dom-config-one.xml | 6 +++++- test/xslt/zebra-dom.cfg | 3 ++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/index/mod_dom.c b/index/mod_dom.c index b1555d7..66f11aa 100644 --- a/index/mod_dom.c +++ b/index/mod_dom.c @@ -1,5 +1,5 @@ -/* $Id: mod_dom.c,v 1.30 2007-03-07 14:18:35 marc Exp $ +/* $Id: mod_dom.c,v 1.31 2007-03-08 17:19:12 marc Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -77,6 +77,7 @@ struct filter_retrieve { struct filter_retrieve *next; }; +#define DOM_INPUT_DOM 0 #define DOM_INPUT_XMLREADER 1 #define DOM_INPUT_MARC 2 struct filter_input { @@ -86,14 +87,17 @@ struct filter_input { int type; union { struct { - const char *input_charset; - yaz_marc_t handle; - yaz_iconv_t iconv; - } marc; + int dummy; + } dom; struct { xmlTextReaderPtr reader; int split_level; } xmlreader; + struct { + const char *input_charset; + yaz_marc_t handle; + yaz_iconv_t iconv; + } marc; } u; struct filter_input *next; }; @@ -235,6 +239,8 @@ static void destroy_dom(struct filter_info *tinfo) { switch(i_ptr->type) { + case DOM_INPUT_DOM: + break; case DOM_INPUT_XMLREADER: if (i_ptr->u.xmlreader.reader) xmlFreeTextReader(i_ptr->u.xmlreader.reader); @@ -462,10 +468,16 @@ static ZEBRA_RES parse_input(struct filter_info *tinfo, xmlNodePtr ptr, parse_convert(tinfo, ptr, &p->convert); break; } + else if (!XML_STRCMP(ptr->name, "xslt")){ + struct filter_input *p + = new_input(tinfo, DOM_INPUT_DOM); + parse_convert(tinfo, ptr, &p->convert); + break; + } else { dom_log(YLOG_WARN, tinfo, ptr, - "bad element <%s>, expected |", + "bad element <%s>, expected ||", ptr->name); return ZEBRA_FAIL; } @@ -631,6 +643,13 @@ static ZEBRA_RES parse_dom(struct filter_info *tinfo, const char *fname) return ZEBRA_FAIL; } } + + /* adding an empty DOM dummy type if no list has been defined */ + if (! tinfo->input_list){ + struct filter_input *p + = new_input(tinfo, DOM_INPUT_DOM); + } + return ZEBRA_OK; } @@ -1179,7 +1198,7 @@ static int extract_xml_split(struct filter_info *tinfo, xmlChar *buf_out = 0; int len_out = 0; xmlDocDumpMemory(doc, &buf_out, &len_out); - yaz_log(YLOG_LOG, "%s: XMLREADER depth: %i\n%.*s", + yaz_log(YLOG_LOG, "%s: XMLREADER level: %i\n%.*s", tinfo->fname ? tinfo->fname : "(none)", depth, len_out, buf_out); xmlFree(buf_out); @@ -1286,12 +1305,16 @@ static int filter_extract(void *clientData, struct recExtractCtrl *p) struct filter_info *tinfo = clientData; struct filter_input *input = tinfo->input_list; - if (!input) - return RECCTRL_EXTRACT_ERROR_GENERIC; + if (!input) + return RECCTRL_EXTRACT_ERROR_GENERIC; + odr_reset(tinfo->odr_record); switch(input->type) { + case DOM_INPUT_DOM: + return extract_xml_full(tinfo, input, p); + break; case DOM_INPUT_XMLREADER: if (input->u.xmlreader.split_level == 0) return extract_xml_full(tinfo, input, p); diff --git a/test/xslt/dom-config-one.xml b/test/xslt/dom-config-one.xml index c7bcaf3..72c81b4 100644 --- a/test/xslt/dom-config-one.xml +++ b/test/xslt/dom-config-one.xml @@ -1,9 +1,13 @@ - + + + + diff --git a/test/xslt/zebra-dom.cfg b/test/xslt/zebra-dom.cfg index fc73eda..1b76e09 100644 --- a/test/xslt/zebra-dom.cfg +++ b/test/xslt/zebra-dom.cfg @@ -3,7 +3,8 @@ profilePath: ${srcdir:-.}:${srcdir:-.}/../../tab modulePath: ../../index/.libs #recordType: dom.dom-config-skipped.xml -recordType: dom.dom-config-col.xml +#recordType: dom.dom-config-col.xml +recordType: dom.dom-config-one.xml #perm.anonymous: rw -- 1.7.10.4