From: Adam Dickmeiss Date: Thu, 23 Feb 2006 11:17:25 +0000 (+0000) Subject: For XML query structure, use 'operator' instead of 'binary'. X-Git-Tag: YAZ.2.1.14~21 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=e637973203a49a536a12a78ec9c8af55b7669fc6;p=yaz-moved-to-github.git For XML query structure, use 'operator' instead of 'binary'. For top-level of query, use .. rather than .. due to XML schemas and other unpleasant things. --- diff --git a/src/xmlquery.c b/src/xmlquery.c index 446dec6..3dd3007 100644 --- a/src/xmlquery.c +++ b/src/xmlquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * All rights reserved. * - * $Id: xmlquery.c,v 1.4 2006-02-19 18:44:23 adam Exp $ + * $Id: xmlquery.c,v 1.5 2006-02-23 11:17:25 adam Exp $ */ /** @@ -207,7 +207,7 @@ xmlNodePtr yaz_query2xml_rpnstructure(const Z_RPNStructure *zs, { Z_Complex *zc = zs->u.complex; - xmlNodePtr node = xmlNewChild(parent, /* NS */ 0, BAD_CAST "binary", 0); + xmlNodePtr node = xmlNewChild(parent, /* NS */ 0, BAD_CAST "operator", 0); if (zc->roperator) yaz_query2xml_operator(zc->roperator, node); yaz_query2xml_rpnstructure(zc->s1, node); @@ -261,8 +261,7 @@ void yaz_rpnquery2xml(const Z_RPNQuery *rpn, void *docp_void) void yaz_query2xml(const Z_Query *q, void *docp_void) { xmlDocPtr *docp = (xmlDocPtr *) docp_void; - xmlNodePtr top_node, child_node = 0; - const char *type = 0; + xmlNodePtr top_node, q_node = 0, child_node = 0; assert(q); assert(docp); @@ -273,31 +272,28 @@ void yaz_query2xml(const Z_Query *q, void *docp_void) { case Z_Query_type_1: case Z_Query_type_101: - type = "rpn"; - child_node = yaz_query2xml_rpn(q->u.type_1, top_node); + q_node = xmlNewChild(top_node, 0, BAD_CAST "rpn", 0); + child_node = yaz_query2xml_rpn(q->u.type_1, q_node); break; case Z_Query_type_2: - type = "ccl"; - child_node = yaz_query2xml_ccl(q->u.type_2, top_node); + q_node = xmlNewChild(top_node, 0, BAD_CAST "ccl", 0); + child_node = yaz_query2xml_ccl(q->u.type_2, q_node); break; case Z_Query_type_100: - type = "z39.58"; - child_node = yaz_query2xml_z3958(q->u.type_100, top_node); + q_node = xmlNewChild(top_node, 0, BAD_CAST "z39.58", 0); + child_node = yaz_query2xml_z3958(q->u.type_100, q_node); break; case Z_Query_type_104: if (q->u.type_104->which == Z_External_CQL) { - type = "cql"; - child_node = yaz_query2xml_cql(q->u.type_104->u.cql, top_node); + q_node = xmlNewChild(top_node, 0, BAD_CAST "cql", 0); + child_node = yaz_query2xml_cql(q->u.type_104->u.cql, q_node); } } - if (child_node && type) + if (child_node && q_node) { *docp = xmlNewDoc(BAD_CAST "1.0"); xmlDocSetRootElement(*docp, top_node); /* make it top node in doc */ - - /* set type attribute now */ - xmlNewProp(top_node, BAD_CAST "type", BAD_CAST type); } else { @@ -672,11 +668,11 @@ void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, if (!ptr || ptr->type != XML_ELEMENT_NODE) { *error_code = 1; - *addinfo = "missing rpn structure node"; + *addinfo = "missing rpn operator, rset, apt node"; return; } *zs = (Z_RPNStructure *) odr_malloc(odr, sizeof(Z_RPNStructure)); - if (!xmlStrcmp(ptr->name, BAD_CAST "binary")) + if (!xmlStrcmp(ptr->name, BAD_CAST "operator")) { Z_Complex *zc = odr_malloc(odr, sizeof(Z_Complex)); @@ -741,8 +737,18 @@ static void yaz_xml2query_(const xmlNode *ptr, Z_Query **query, ODR odr, if (ptr && ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST "query")) { - const char *type = (const char *) - xmlGetProp((xmlNodePtr) ptr, BAD_CAST "type"); + const char *type; + ptr = ptr->children; + while (ptr && ptr->type != XML_ELEMENT_NODE) + ptr = ptr->next; + if (!ptr || ptr->type != XML_ELEMENT_NODE) + { + *error_code = 1; + *addinfo = "missing query content"; + return; + } + type = (const char *) ptr->name; + *query = (Z_Query*) odr_malloc(odr, sizeof(Z_Query)); if (!type || !strcmp(type, "rpn")) { diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index 7ed5477..aea6177 100644 --- a/test/tstxmlquery.c +++ b/test/tstxmlquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tstxmlquery.c,v 1.9 2006-02-19 18:44:23 adam Exp $ + * $Id: tstxmlquery.c,v 1.10 2006-02-23 11:17:25 adam Exp $ */ #include @@ -111,64 +111,64 @@ static void tst() YAZ_CHECK_EQ(pqf2xml_text( "@attr 1=4 computer", "\n" - "" + "" "" "computer" - "\n", + "\n", "RPN: @attrset Bib-1 @attr 1=4 computer" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@attr 2=1 @attr 1=title computer", "\n" - "" + "" "" "" "computer" - "\n", + "\n", "RPN: @attrset Bib-1 @attr \"1=title\" @attr 2=1 computer" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@attr 2=1 @attr exp1 1=1 computer", "\n" - "" + "" "" "" "computer" - "\n", + "\n", "RPN: @attrset Bib-1 @attr Exp-1 1=1 @attr 2=1 computer" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@and a b", "\n" - "" - "" + "" + "" "a" "b" - "\n", + "\n", "RPN: @attrset Bib-1 @and a b" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@or @and a b c", "\n" - "" - "" - "" + "" + "" + "" "a" - "b" + "b" "c" - "\n", + "\n", "RPN: @attrset Bib-1 @or @and a b c" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@set abe", "\n" - "" - "abe\n", + "" + "abe\n", "RPN: @attrset Bib-1 @set abe" ), XML_MATCH); @@ -177,56 +177,56 @@ static void tst() knownunit, proxunit */ "@prox 0 3 1 2 k 2 a b", "\n" - "" - "" + "" "a" "b" - "\n", + "\n", "RPN: @attrset Bib-1 @prox 0 3 1 2 k 2 a b" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term numeric 32", "\n" - "" + "" "" "32" - "\n", + "\n", "RPN: @attrset Bib-1 @term numeric 32" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term string computer", "\n" - "" + "" "" "computer" - "\n", + "\n", "RPN: @attrset Bib-1 @term string computer" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term null void", "\n" - "" + "" "" "" - "\n", + "\n", "RPN: @attrset Bib-1 @term null x" ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@attrset gils @attr 4=2 x", "\n" - "" + "" "" "" "x" - "\n", + "\n", "RPN: @attrset GILS @attr 4=2 x" ), XML_MATCH); #endif