2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.3 1997/09/17 12:10:37 adam
13 * Revision 1.2 1997/04/30 08:52:11 quinn
16 * Revision 1.1 1996/10/08 10:43:20 quinn
22 #include <yaz/wrbuf.h>
23 #include <yaz/data1.h>
26 * This module generates SOIF (Simple Object Interchange Format) records
27 * from d1-nodes. nested elements are flattened out, depth first, by
28 * concatenating the tag names at each level.
31 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
36 for (c = n->child; c; c = c->next)
40 if (c->which == DATA1N_tag)
42 if (select && !c->u.tag.node_selected)
44 if (c->u.tag.element && c->u.tag.element->tag)
45 tag = c->u.tag.element->tag->names->name; /* first name */
47 tag = c->u.tag.tag; /* local string tag */
50 sprintf(tmp, "%s-%s", prefix, tag);
54 if (nodetoelement(c, select, tmp, b) < 0)
57 else if (c->which == DATA1N_data)
59 char *p = c->u.data.data;
60 int l = c->u.data.len;
62 wrbuf_write(b, prefix, strlen(prefix));
64 sprintf(tmp, "{%d}:\t", l);
65 wrbuf_write(b, tmp, strlen(tmp));
73 char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len)
75 WRBUF b = data1_get_wrbuf (dh);
80 if (n->which != DATA1N_root)
82 sprintf(buf, "@%s{\n", n->u.root.type);
83 wrbuf_write(b, buf, strlen(buf));
84 if (nodetoelement(n, select, "", b))
86 wrbuf_write(b, "}\n", 2);