From 465343e3b3f2cd797e018b26df19c91a39cbeccf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 2 Feb 2006 15:00:58 +0000 Subject: [PATCH] Supply Term type as attribute in XML RPN representation. --- src/xmlquery.c | 27 +++++++++++++++++++++++---- test/tstxmlquery.c | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/xmlquery.c b/src/xmlquery.c index b83449f..18800f2 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.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; } diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index dd6729e..fb0fddb 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.7 2006-01-31 11:01:26 adam Exp $ + * $Id: tstxmlquery.c,v 1.8 2006-02-02 15:00:58 adam Exp $ */ #include @@ -88,7 +88,7 @@ void tst() "\n" "" "" - "computer" + "computer" "\n"), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( @@ -97,7 +97,7 @@ void tst() "" "" "" - "computer" + "computer" "\n"), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( @@ -106,7 +106,7 @@ void tst() "" "" "" - "computer" + "computer" "\n"), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( @@ -114,7 +114,8 @@ void tst() "\n" "" "" - "ab" + "a" + "b" "\n"), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( @@ -122,9 +123,10 @@ void tst() "\n" "" "" - "a" - "b" - "c" + "" + "a" + "b" + "c" "\n"), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( @@ -144,9 +146,34 @@ void tst() "ordered=\"true\" " "relationType=\"2\" " "knownProximityUnit=\"2\">" - "ab" + "a" + "b" "\n"), XML_MATCH); + YAZ_CHECK_EQ(pqf2xml_text( + "@term numeric 32", + "\n" + "" + "" + "32" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@term string computer", + "\n" + "" + "" + "computer" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@term null void", + "\n" + "" + "" + "" + "\n"), XML_MATCH); + #endif } -- 1.7.10.4