1 /* $Id: d1_soif.c,v 1.4 2005-01-15 19:38:18 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 * This module generates SOIF (Simple Object Interchange Format) records
26 * from d1-nodes. nested elements are flattened out, depth first, by
27 * concatenating the tag names at each level.
30 #include <yaz/wrbuf.h>
31 #include <idzebra/data1.h>
33 static int nodetoelement(data1_node *n, int select, char *prefix, WRBUF b)
38 for (c = n->child; c; c = c->next)
42 if (c->which == DATA1N_tag)
44 if (select && !c->u.tag.node_selected)
46 if (c->u.tag.element && c->u.tag.element->tag)
47 tag = c->u.tag.element->tag->names->name; /* first name */
49 tag = c->u.tag.tag; /* local string tag */
52 sprintf(tmp, "%s-%s", prefix, tag);
56 if (nodetoelement(c, select, tmp, b) < 0)
59 else if (c->which == DATA1N_data)
61 char *p = c->u.data.data;
62 int l = c->u.data.len;
64 wrbuf_write(b, prefix, strlen(prefix));
66 sprintf(tmp, "{%d}:\t", l);
67 wrbuf_write(b, tmp, strlen(tmp));
75 char *data1_nodetosoif (data1_handle dh, data1_node *n, int select, int *len)
77 WRBUF b = data1_get_wrbuf (dh);
82 if (n->which != DATA1N_root)
84 sprintf(buf, "@%s{\n", n->u.root.type);
85 wrbuf_write(b, buf, strlen(buf));
86 if (nodetoelement(n, select, "", b))
88 wrbuf_write(b, "}\n", 2);