-/* $Id: d1_handle.c,v 1.7 2005-01-15 19:38:18 adam Exp $
+/* $Id: d1_handle.c,v 1.8 2006-03-29 10:43:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <yaz/log.h>
#include <idzebra/data1.h>
+#define DATA1_FLAG_XML 1
+
struct data1_handle_info {
WRBUF wrbuf;
char *tab_path;
int map_len;
NMEM mem;
- int flags;
};
-data1_handle data1_create (void)
-{
- return data1_createx(0);
-}
-
-data1_handle data1_createx (int flags)
+data1_handle data1_create(void)
{
data1_handle p = (data1_handle)xmalloc (sizeof(*p));
if (!p)
p->absyn_cache = NULL;
p->attset_cache = NULL;
p->mem = nmem_create ();
- p->flags = flags;
return p;
}
int data1_is_xmlmode(data1_handle dh)
{
- return dh->flags & DATA1_FLAG_XML;
+ return 1;
}
-/* $Id: d1_write.c,v 1.6 2005-01-15 19:38:18 adam Exp $
+/* $Id: d1_write.c,v 1.7 2006-03-29 10:43:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
}
}
+static void wrbuf_write_tag(WRBUF b, const char *tag, int opening)
+{
+ int i, fixup = 0;
+
+ /* see if we must fix the tag.. The grs.marc filter produces
+ a data1 tree with not well-formed XML */
+ if (*tag >= '0' && *tag <= '9')
+ fixup = 1;
+ for (i = 0; tag[i]; i++)
+ if (strchr( " <>$,()[]", tag[i]))
+ fixup = 1;
+ if (fixup)
+ {
+ wrbuf_puts(b, "tag");
+ if (opening)
+ {
+ wrbuf_puts(b, " value=\"");
+ wrbuf_xmlputs(b, tag);
+ wrbuf_puts(b, "\"");
+ }
+ }
+ else
+ wrbuf_puts(b, tag);
+}
+
static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col,
int pretty_format)
{
{
if (pretty_format)
indent (b, col);
- wrbuf_puts (b, "<");
- wrbuf_xmlputs (b, tag);
+ wrbuf_puts(b, "<");
+ wrbuf_write_tag(b, tag, 1);
wrbuf_put_xattr (b, c->u.tag.attributes);
wrbuf_puts(b, ">");
if (pretty_format)
if (pretty_format)
indent (b, col);
wrbuf_puts(b, "</");
- wrbuf_xmlputs(b, tag);
+ wrbuf_write_tag(b, tag, 0);
wrbuf_puts(b, ">");
if (pretty_format)
wrbuf_puts (b, "\n");
if (!data1_is_xmlmode (dh))
{
wrbuf_puts (b, "<");
- wrbuf_puts (b, n->u.root.type);
+ wrbuf_write_tag(b, n->u.root.type, 1);
wrbuf_puts (b, ">\n");
}
if (nodetoidsgml(n, select, b, 0, 0 /* no pretty format */))
if (!data1_is_xmlmode (dh))
{
wrbuf_puts (b, "</");
- wrbuf_puts (b, n->u.root.type);
+ wrbuf_write_tag(b, n->u.root.type, 0);
wrbuf_puts (b, ">\n");
}
*len = wrbuf_len(b);
-/* $Id: data1.h,v 1.10 2005-06-23 06:45:46 adam Exp $
+/* $Id: data1.h,v 1.11 2006-03-29 10:43:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
YAZ_EXPORT data1_handle data1_create (void);
-#define DATA1_FLAG_XML 1
-YAZ_EXPORT data1_handle data1_createx (int flags);
YAZ_EXPORT void data1_destroy(data1_handle dh);
YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n);
-/* $Id: zebraapi.c,v 1.207 2006-03-28 12:39:07 adam Exp $
+/* $Id: zebraapi.c,v 1.208 2006-03-29 10:43:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
yaz_log (YLOG_DEBUG, "zebra_register_open rw=%d useshadow=%d p=%p n=%s rp=%s",
rw, useshadow, reg, name, reg_path ? reg_path : "(none)");
- reg->dh = data1_createx (DATA1_FLAG_XML);
+ reg->dh = data1_create();
if (!reg->dh)
{
xfree(reg->name);