-/* $Id: xmlread.c,v 1.10 2003-09-08 09:50:04 adam Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+/* $Id: xmlread.c,v 1.15 2004-09-28 10:15:03 adam Exp $
+ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
This file is part of the Zebra server.
#include <yaz/log.h>
-#include "grsread.h"
+#include <idzebra/recgrs.h>
#include <yaz/xmalloc.h>
#include <yaz/log.h>
-#include <data1.h>
#include <expat.h>
ui->d1_stack[ui->level -1]);
}
-static void cb_decl (void *user, const char *version, const char*encoding,
+static void cb_decl (void *user, const char *version, const char *encoding,
int standalone)
{
struct user_info *ui = (struct user_info*) user;
attr_list[1] = version;
attr_list[2] = "encoding";
- attr_list[3] = "UTF-8"; /* encoding */
+ attr_list[3] = "UTF-8"; /* internally it's always UTF-8 */
attr_list[4] = "standalone";
attr_list[5] = standalone ? "yes" : "no";
data1_mk_preprocess (ui->dh, ui->nmem, "xml", attr_list,
ui->d1_stack[ui->level-1]);
- yaz_log (ui->loglevel, "decl version=%s encoding=%s",
+#if 0
+ yaz_log (LOG_LOG, "decl version=%s encoding=%s",
version ? version : "null",
encoding ? encoding : "null");
+#endif
}
static void cb_processing (void *user, const char *target,
yaz_log (ui->loglevel, "decl processing target=%s data=%s",
target ? target : "null",
data ? data : "null");
-
-
}
static void cb_comment (void *user, const char *data)
XML_Parser parser;
struct user_info uinfo;
int done = 0;
+ data1_node *first_node;
uinfo.loglevel = LOG_DEBUG;
uinfo.level = 1;
XML_ParserFree (parser);
if (!uinfo.d1_stack[1] || !done)
return 0;
+ /* insert XML header if not present .. */
+ first_node = uinfo.d1_stack[0]->child;
+ if (first_node->which != DATA1N_preprocess ||
+ strcmp(first_node->u.preprocess.target, "xml"))
+ {
+ const char *attr_list[5];
+
+ attr_list[0] = "version";
+ attr_list[1] = "1.0";
+
+ attr_list[2] = "encoding";
+ attr_list[3] = "UTF-8"; /* encoding */
+
+ attr_list[4] = 0;
+
+ data1_insert_preprocess (uinfo.dh, uinfo.nmem, "xml", attr_list,
+ uinfo.d1_stack[0]);
+ }
return uinfo.d1_stack[0];
}
XML_Expat_Version expat_version;
};
-static void *grs_init_xml(void)
+static data1_node *grs_read_xml (struct grs_read_info *p)
+{
+ return zebra_read_xml (p->dh, p->readf, p->fh, p->mem);
+}
+
+static void *init_xml(Res res, RecType recType)
{
struct xml_info *p = (struct xml_info *) xmalloc (sizeof(*p));
return p;
}
-static data1_node *grs_read_xml (struct grs_read_info *p)
+static void destroy_xml(void *clientData)
{
- return zebra_read_xml (p->dh, p->readf, p->fh, p->mem);
+ struct xml_info *p = (struct xml_info *) clientData;
+
+ xfree (p);
}
-static void grs_destroy_xml(void *clientData)
+static int extract_xml(void *clientData, struct recExtractCtrl *ctrl)
{
- struct xml_info *p = (struct xml_info *) clientData;
+ return zebra_grs_extract(clientData, ctrl, grs_read_xml);
+}
- xfree (p);
+static int retrieve_xml(void *clientData, struct recRetrieveCtrl *ctrl)
+{
+ return zebra_grs_retrieve(clientData, ctrl, grs_read_xml);
}
-static struct recTypeGrs xml_type = {
- "xml",
- grs_init_xml,
- grs_destroy_xml,
- grs_read_xml
+static struct recType xml_type = {
+ "grs.xml",
+ init_xml,
+ 0,
+ destroy_xml,
+ extract_xml,
+ retrieve_xml,
};
-RecTypeGrs recTypeGrs_xml = &xml_type;
+RecType
+#ifdef IDZEBRA_STATIC_GRS_XML
+idzebra_filter_grs_xml
+#else
+idzebra_filter
+#endif
-/* HAVE_EXPAT_H */
+[] = {
+ &xml_type,
+ 0,
+};
+
#endif