2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1996-10-08 10:43:20 quinn
18 * This module generates SOIF (Simple Object Interchange Format) records
19 * from d1-nodes. nested elements are flattened out, depth first, by
20 * concatenating the tag names at each level.
23 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
28 for (c = n->child; c; c = c->next)
32 if (c->which == DATA1N_tag)
34 if (select && !c->u.tag.node_selected)
36 if (c->u.tag.element && c->u.tag.element->tag)
37 tag = c->u.tag.element->tag->names->name; /* first name */
39 tag = c->u.tag.tag; /* local string tag */
42 sprintf(tmp, "%s-%s", prefix, tag);
46 if (nodetoelement(c, select, tmp, b) < 0)
49 else if (c->which == DATA1N_data)
51 char *p = c->u.data.data;
52 int l = c->u.data.len;
54 wrbuf_write(b, prefix, strlen(prefix));
56 sprintf(tmp, "{%d}:\t", l);
57 wrbuf_write(b, tmp, strlen(tmp));
65 char *data1_nodetosoif(data1_node *n, int select, int *len)
75 if (n->which != DATA1N_root)
77 sprintf(buf, "@%s{\n", n->u.root.type);
78 wrbuf_write(b, buf, strlen(buf));
79 if (nodetoelement(n, select, "", b))
81 wrbuf_write(b, "}\n", 2);