Supply Term type as attribute in XML RPN representation.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Feb 2006 15:00:58 +0000 (15:00 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Feb 2006 15:00:58 +0000 (15:00 +0000)
src/xmlquery.c
test/tstxmlquery.c

index b83449f..18800f2 100644 (file)
@@ -2,7 +2,7 @@
  * 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 $
  */
 
 /**
@@ -83,26 +83,45 @@ xmlNodePtr yaz_query2xml_term(const Z_Term *term,
     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;
 }
 
index dd6729e..fb0fddb 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
@@ -88,7 +88,7 @@ void tst()
                      "<?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(
@@ -97,7 +97,7 @@ void tst()
                      "<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(
@@ -106,7 +106,7 @@ void tst()
                      "<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(
@@ -114,7 +114,8 @@ void tst()
                      "<?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(
@@ -122,9 +123,10 @@ void tst()
                      "<?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(
@@ -144,9 +146,34 @@ void tst()
                      "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
 }