Remove the oid_name_to_dotstring() function, which is now in oid.c
[yaz-moved-to-github.git] / zutil / srw.c
index 68f7912..5b6657e 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.11 2003-03-23 20:27:16 adam Exp $
+ * $Id: srw.c,v 1.15 2003-05-12 22:36:10 adam Exp $
  */
 
 #include <yaz/srw.h>
@@ -101,6 +101,33 @@ static int match_xsd_string(xmlNodePtr ptr, const char *elem, ODR o,
 {
     return match_xsd_string_n(ptr, elem, o, val, 0);
 }
+
+static int match_xsd_XML_n(xmlNodePtr ptr, const char *elem, ODR o,
+                           char **val, int *len)
+{
+    xmlBufferPtr buf;
+
+    if (!match_element(ptr, elem))
+        return 0;
+    ptr = ptr->children;
+    if (!ptr)
+        return 0;
+    buf = xmlBufferCreate();
+
+    xmlNodeDump(buf, ptr->doc, ptr, 0, 0);
+
+    *val = odr_malloc(o, buf->use+1);
+    memcpy (*val, buf->content, buf->use);
+    (*val)[buf->use] = '\0';
+
+    if (len)
+        *len = buf->use;
+
+    xmlBufferFree(buf);
+
+    return 1;
+}
+
                      
 static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, int **val)
 {
@@ -169,6 +196,10 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs,
                                                 &(*recs)[i].recordData_buf,
                                                 &(*recs)[i].recordData_len))
                         ;
+                    else if (match_xsd_XML_n(rptr, "recordXML", o, 
+                                             &(*recs)[i].recordData_buf,
+                                             &(*recs)[i].recordData_len))
+                        (*recs)[i].recordPacking = Z_SRW_recordPacking_XML;
                     else if (match_xsd_integer(rptr, "recordPosition", o, 
                                                &(*recs)[i].recordPosition))
                         ;
@@ -373,6 +404,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
         {
             Z_SRW_PDU **p = handler_data;
             Z_SRW_explainResponse *res;
+            xmlNodePtr ptr = method->children;
 
             *p = odr_malloc(o, sizeof(**p));
             (*p)->which = Z_SRW_explain_response;
@@ -380,8 +412,12 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
             res->explainData_buf = 0;
             res->explainData_len = 0;
             res->explainPacking = Z_SRW_recordPacking_string;
-            match_xsd_string_n(method, "explainResponse", o,
-                               &res->explainData_buf, &res->explainData_len);
+            for (; ptr; ptr = ptr->next)
+            {
+                match_xsd_string_n(ptr, "Explain", o, 
+                                   &res->explainData_buf,
+                                   &res->explainData_len);
+            }
         }
         else
             return -1;
@@ -455,7 +491,6 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
         }
         else if ((*p)->which == Z_SRW_explain_request)
         {
-            Z_SRW_explainRequest *req = (*p)->u.explain_request;
             xmlNodePtr ptr = xmlNewChild(pptr, 0, "explainRequest", 0);
             xmlNsPtr ns_srw = xmlNewNs(ptr, ns, "zs");
 
@@ -469,12 +504,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
 
             xmlSetNs(ptr, ns_srw);
 
-            if (res->explainData_buf)
-            {
-                xmlNodePtr t = xmlNewTextLen(res->explainData_buf,
-                                             res->explainData_len);
-                xmlAddChild(ptr, t);
-            }
+            add_xsd_string_n(ptr, "Explain", res->explainData_buf,
+                             res->explainData_len);
         }
         else
             return -1;