* Copyright (C) 1995-2005, Index Data ApS
* All rights reserved.
*
- * $Id: xmlquery.c,v 1.2 2006-01-30 14:02:07 adam Exp $
+ * $Id: xmlquery.c,v 1.3 2006-02-02 15:00:58 adam Exp $
*/
/**
xmlNodePtr t = 0;
xmlNodePtr node = xmlNewChild(parent, /* NS */ 0, BAD_CAST "term", 0);
char formstr[20];
+ const char *type = 0;
switch (term->which)
{
case Z_Term_general:
+ type = "general";
t = xmlNewTextLen(BAD_CAST term->u.general->buf, term->u.general->len);
break;
- case Z_Term_characterString:
- t = xmlNewText(BAD_CAST term->u.characterString);
- break;
case Z_Term_numeric:
+ type = "numeric";
sprintf(formstr, "%d", *term->u.numeric);
t = xmlNewText(BAD_CAST formstr);
break;
+ case Z_Term_characterString:
+ type = "string";
+ t = xmlNewText(BAD_CAST term->u.characterString);
+ break;
+ case Z_Term_oid:
+ type = "oid";
+ break;
+ case Z_Term_dateTime:
+ type = "dateTime";
+ break;
+ case Z_Term_external:
+ type = "external";
+ break;
+ case Z_Term_integerAndUnit:
+ type ="integerAndUnit";
+ break;
case Z_Term_null:
+ type = "null";
break;
default:
break;
}
if (t) /* got a term node ? */
xmlAddChild(node, t);
+ if (type)
+ xmlNewProp(node, BAD_CAST "type", BAD_CAST type);
return node;
}
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstxmlquery.c,v 1.7 2006-01-31 11:01:26 adam Exp $
+ * $Id: tstxmlquery.c,v 1.8 2006-02-02 15:00:58 adam Exp $
*/
#include <stdlib.h>
"<?xml version=\"1.0\"?>\n"
"<query set=\"Bib-1\" type=\"rpn\">"
"<apt><attr type=\"1\" value=\"4\"/>"
- "<term>computer</term></apt>"
+ "<term type=\"general\">computer</term></apt>"
"</query>\n"), XML_MATCH);
YAZ_CHECK_EQ(pqf2xml_text(
"<query set=\"Bib-1\" type=\"rpn\">"
"<apt><attr type=\"1\" value=\"title\"/>"
"<attr type=\"2\" value=\"1\"/>"
- "<term>computer</term></apt>"
+ "<term type=\"general\">computer</term></apt>"
"</query>\n"), XML_MATCH);
YAZ_CHECK_EQ(pqf2xml_text(
"<query set=\"Bib-1\" type=\"rpn\">"
"<apt><attr set=\"Exp-1\" type=\"1\" value=\"1\"/>"
"<attr type=\"2\" value=\"1\"/>"
- "<term>computer</term></apt>"
+ "<term type=\"general\">computer</term></apt>"
"</query>\n"), XML_MATCH);
YAZ_CHECK_EQ(pqf2xml_text(
"<?xml version=\"1.0\"?>\n"
"<query set=\"Bib-1\" type=\"rpn\">"
"<binary type=\"and\">"
- "<apt><term>a</term></apt><apt><term>b</term></apt>"
+ "<apt><term type=\"general\">a</term></apt>"
+ "<apt><term type=\"general\">b</term></apt>"
"</binary></query>\n"), XML_MATCH);
YAZ_CHECK_EQ(pqf2xml_text(
"<?xml version=\"1.0\"?>\n"
"<query set=\"Bib-1\" type=\"rpn\">"
"<binary type=\"or\">"
- "<binary type=\"and\"><apt><term>a</term></apt>"
- "<apt><term>b</term></apt></binary>"
- "<apt><term>c</term></apt>"
+ "<binary type=\"and\">"
+ "<apt><term type=\"general\">a</term></apt>"
+ "<apt><term type=\"general\">b</term></apt></binary>"
+ "<apt><term type=\"general\">c</term></apt>"
"</binary></query>\n"), XML_MATCH);
YAZ_CHECK_EQ(pqf2xml_text(
"ordered=\"true\" "
"relationType=\"2\" "
"knownProximityUnit=\"2\">"
- "<apt><term>a</term></apt><apt><term>b</term></apt>"
+ "<apt><term type=\"general\">a</term></apt>"
+ "<apt><term type=\"general\">b</term></apt>"
"</binary></query>\n"), XML_MATCH);
+ YAZ_CHECK_EQ(pqf2xml_text(
+ "@term numeric 32",
+ "<?xml version=\"1.0\"?>\n"
+ "<query set=\"Bib-1\" type=\"rpn\">"
+ "<apt>"
+ "<term type=\"numeric\">32</term></apt>"
+ "</query>\n"), XML_MATCH);
+
+ YAZ_CHECK_EQ(pqf2xml_text(
+ "@term string computer",
+ "<?xml version=\"1.0\"?>\n"
+ "<query set=\"Bib-1\" type=\"rpn\">"
+ "<apt>"
+ "<term type=\"string\">computer</term></apt>"
+ "</query>\n"), XML_MATCH);
+
+ YAZ_CHECK_EQ(pqf2xml_text(
+ "@term null void",
+ "<?xml version=\"1.0\"?>\n"
+ "<query set=\"Bib-1\" type=\"rpn\">"
+ "<apt>"
+ "<term type=\"null\"/></apt>"
+ "</query>\n"), XML_MATCH);
+
#endif
}