1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 Index Data
3 * See the file LICENSE for details.
5 /** \file cclxmlconfig.c
6 \brief XML configuration for CCL
16 #include <yaz/ccl_xml.h>
20 static int ccl_xml_config_combqual(WRBUF wrbuf,
24 struct _xmlAttr *attr;
26 for (attr = ptr->properties; attr; attr = attr->next)
28 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
29 attr->children && attr->children->type == XML_TEXT_NODE)
30 name = (const char *) attr->children->content;
33 *addinfo = "bad attribute for 'attr'. "
34 "Expecting 'type', 'value', or 'attrset'";
40 *addinfo = "missing attribute for 'name' for element 'qual'";
43 wrbuf_printf(wrbuf, "%s", name);
49 static int ccl_xml_config_attr(const char *default_set,
54 struct _xmlAttr *attr;
56 const char *value = 0;
57 const char *attrset = default_set;
58 for (attr = ptr->properties; attr; attr = attr->next)
60 if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
61 attr->children && attr->children->type == XML_TEXT_NODE)
62 type = (const char *) attr->children->content;
63 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
64 attr->children && attr->children->type == XML_TEXT_NODE)
65 value = (const char *) attr->children->content;
66 else if (!xmlStrcmp(attr->name, BAD_CAST "attrset") &&
67 attr->children && attr->children->type == XML_TEXT_NODE)
68 attrset = (const char *) attr->children->content;
71 *addinfo = "bad attribute for 'attr'. "
72 "Expecting 'type', 'value', or 'attrset'";
78 *addinfo = "missing attribute for 'type' for element 'attr'";
83 *addinfo = "missing attribute for 'value' for element 'attr'";
87 wrbuf_printf(wrbuf, "%s,%s=%s", attrset, type, value);
89 wrbuf_printf(wrbuf, "%s=%s", type, value);
93 static int ccl_xml_config_qual(CCL_bibset bibset, const char *default_set,
98 struct _xmlAttr *attr;
100 const xmlNode *a_ptr = ptr->children;
101 for (attr = ptr->properties; attr; attr = attr->next)
103 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
104 attr->children && attr->children->type == XML_TEXT_NODE)
105 name = (const char *) attr->children->content;
108 *addinfo = "bad attribute for 'qual'. Expecting 'name' only";
114 *addinfo = "missing attribute 'name' for 'qual' element";
117 for (; a_ptr; a_ptr = a_ptr->next)
119 if (a_ptr->type == XML_ELEMENT_NODE)
121 if (!xmlStrcmp(a_ptr->name, BAD_CAST "attr"))
123 int r = ccl_xml_config_attr(default_set, wrbuf,
127 wrbuf_printf(wrbuf, " ");
129 else if (!xmlStrcmp(a_ptr->name, BAD_CAST "qual"))
131 int r = ccl_xml_config_combqual(wrbuf, a_ptr, addinfo);
134 wrbuf_printf(wrbuf, " ");
138 *addinfo = "bad element: expecting 'attr'";
143 ccl_qual_fitem(bibset, wrbuf_cstr(wrbuf), name);
147 int ccl_xml_config_directive(CCL_bibset bibset, const xmlNode *ptr,
148 const char **addinfo)
150 struct _xmlAttr *attr;
151 const char *name = 0;
152 const char *value = 0;
153 for (attr = ptr->properties; attr; attr = attr->next)
155 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
156 attr->children && attr->children->type == XML_TEXT_NODE)
157 name = (const char *) attr->children->content;
158 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
159 attr->children && attr->children->type == XML_TEXT_NODE)
160 value = (const char *) attr->children->content;
163 *addinfo = "bad attribute for 'diretive'. "
164 "Expecting 'name' or 'value'";
170 *addinfo = "missing attribute 'name' for 'directive' element";
175 *addinfo = "missing attribute 'name' for 'value' element";
178 ccl_qual_add_special(bibset, name, value);
182 int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, const char **addinfo)
184 if (ptr && ptr->type == XML_ELEMENT_NODE &&
185 !xmlStrcmp(ptr->name, BAD_CAST "cclmap"))
187 const xmlNode *c_ptr;
189 struct _xmlAttr *attr;
190 for (attr = ptr->properties; attr; attr = attr->next)
192 if (!xmlStrcmp(attr->name, BAD_CAST "defaultattrset") &&
193 attr->children && attr->children->type == XML_TEXT_NODE)
194 set = (const char *) attr->children->content;
197 *addinfo = "bad attribute for 'cclmap'. "
198 "expecting 'defaultattrset'";
202 for (c_ptr = ptr->children; c_ptr; c_ptr = c_ptr->next)
204 if (c_ptr->type == XML_ELEMENT_NODE)
206 if (!xmlStrcmp(c_ptr->name, BAD_CAST "qual"))
208 WRBUF wrbuf = wrbuf_alloc();
209 int r = ccl_xml_config_qual(bibset, set,
210 wrbuf, c_ptr, addinfo);
211 wrbuf_destroy(wrbuf);
215 else if (!xmlStrcmp(c_ptr->name, BAD_CAST "directive"))
217 int r = ccl_xml_config_directive(bibset, c_ptr, addinfo);
223 *addinfo = "bad element for 'cclmap'. "
224 "expecting 'directive' or 'qual'";
237 * c-file-style: "Stroustrup"
238 * indent-tabs-mode: nil
240 * vim: shiftwidth=4 tabstop=8 expandtab