1 /* This file is part of the Zebra server.
2 Copyright (C) 1995-2008 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * This module generates SOIF (Simple Object Interchange Format) records
23 * from d1-nodes. nested elements are flattened out, depth first, by
24 * concatenating the tag names at each level.
27 #include <yaz/wrbuf.h>
28 #include <idzebra/data1.h>
30 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
35 for (c = n->child; c; c = c->next)
39 if (c->which == DATA1N_tag)
41 if (select && !c->u.tag.node_selected)
43 if (c->u.tag.element && c->u.tag.element->tag)
44 tag = c->u.tag.element->tag->names->name; /* first name */
46 tag = c->u.tag.tag; /* local string tag */
49 sprintf(tmp, "%s-%s", prefix, tag);
53 if (nodetoelement(c, select, tmp, b) < 0)
56 else if (c->which == DATA1N_data)
58 char *p = c->u.data.data;
59 int l = c->u.data.len;
61 wrbuf_write(b, prefix, strlen(prefix));
63 sprintf(tmp, "{%d}:\t", l);
64 wrbuf_write(b, tmp, strlen(tmp));
72 char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len)
74 WRBUF b = data1_get_wrbuf (dh);
79 if (n->which != DATA1N_root)
81 sprintf(buf, "@%s{\n", n->u.root.type);
82 wrbuf_write(b, buf, strlen(buf));
83 if (nodetoelement(n, select, "", b))
85 wrbuf_write(b, "}\n", 2);
92 * indent-tabs-mode: nil
94 * vim: shiftwidth=4 tabstop=8 expandtab