1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
6 /** \file cclxmlconfig.c
7 \brief XML configuration for CCL
14 #include <yaz/ccl_xml.h>
18 static int ccl_xml_config_combqual(WRBUF wrbuf,
22 struct _xmlAttr *attr;
24 for (attr = ptr->properties; attr; attr = attr->next)
26 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
27 attr->children && attr->children->type == XML_TEXT_NODE)
28 name = (const char *) attr->children->content;
31 *addinfo = "bad attribute for 'attr'. "
32 "Expecting 'type', 'value', or 'attrset'";
38 *addinfo = "missing attribute for 'name' for element 'qual'";
41 wrbuf_printf(wrbuf, "%s", name);
47 static int ccl_xml_config_attr(const char *default_set,
52 struct _xmlAttr *attr;
54 const char *value = 0;
55 const char *attrset = default_set;
56 for (attr = ptr->properties; attr; attr = attr->next)
58 if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
59 attr->children && attr->children->type == XML_TEXT_NODE)
60 type = (const char *) attr->children->content;
61 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
62 attr->children && attr->children->type == XML_TEXT_NODE)
63 value = (const char *) attr->children->content;
64 else if (!xmlStrcmp(attr->name, BAD_CAST "attrset") &&
65 attr->children && attr->children->type == XML_TEXT_NODE)
66 attrset = (const char *) attr->children->content;
69 *addinfo = "bad attribute for 'attr'. "
70 "Expecting 'type', 'value', or 'attrset'";
76 *addinfo = "missing attribute for 'type' for element 'attr'";
81 *addinfo = "missing attribute for 'value' for element 'attr'";
85 wrbuf_printf(wrbuf, "%s,%s=%s", attrset, type, value);
87 wrbuf_printf(wrbuf, "%s=%s", type, value);
91 static int ccl_xml_config_qual(CCL_bibset bibset, const char *default_set,
96 struct _xmlAttr *attr;
98 const xmlNode *a_ptr = ptr->children;
99 for (attr = ptr->properties; attr; attr = attr->next)
101 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
102 attr->children && attr->children->type == XML_TEXT_NODE)
103 name = (const char *) attr->children->content;
106 *addinfo = "bad attribute for 'qual'. Expecting 'name' only";
112 *addinfo = "missing attribute 'name' for 'qual' element";
115 for (; a_ptr; a_ptr = a_ptr->next)
117 if (a_ptr->type == XML_ELEMENT_NODE)
119 if (!xmlStrcmp(a_ptr->name, BAD_CAST "attr"))
121 int r = ccl_xml_config_attr(default_set, wrbuf,
125 wrbuf_printf(wrbuf, " ");
127 else if (!xmlStrcmp(a_ptr->name, BAD_CAST "qual"))
129 int r = ccl_xml_config_combqual(wrbuf, a_ptr, addinfo);
132 wrbuf_printf(wrbuf, " ");
136 *addinfo = "bad element: expecting 'attr'";
141 ccl_qual_fitem(bibset, wrbuf_cstr(wrbuf), name);
145 int ccl_xml_config_directive(CCL_bibset bibset, const xmlNode *ptr,
146 const char **addinfo)
148 struct _xmlAttr *attr;
149 const char *name = 0;
150 const char *value = 0;
151 for (attr = ptr->properties; attr; attr = attr->next)
153 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
154 attr->children && attr->children->type == XML_TEXT_NODE)
155 name = (const char *) attr->children->content;
156 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
157 attr->children && attr->children->type == XML_TEXT_NODE)
158 value = (const char *) attr->children->content;
161 *addinfo = "bad attribute for 'diretive'. "
162 "Expecting 'name' or 'value'";
168 *addinfo = "missing attribute 'name' for 'directive' element";
173 *addinfo = "missing attribute 'name' for 'value' element";
176 ccl_qual_add_special(bibset, name, value);
180 int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, const char **addinfo)
182 if (ptr && ptr->type == XML_ELEMENT_NODE &&
183 !xmlStrcmp(ptr->name, BAD_CAST "cclmap"))
185 const xmlNode *c_ptr;
187 struct _xmlAttr *attr;
188 for (attr = ptr->properties; attr; attr = attr->next)
190 if (!xmlStrcmp(attr->name, BAD_CAST "defaultattrset") &&
191 attr->children && attr->children->type == XML_TEXT_NODE)
192 set = (const char *) attr->children->content;
195 *addinfo = "bad attribute for 'cclmap'. "
196 "expecting 'defaultattrset'";
200 for (c_ptr = ptr->children; c_ptr; c_ptr = c_ptr->next)
202 if (c_ptr->type == XML_ELEMENT_NODE)
204 if (!xmlStrcmp(c_ptr->name, BAD_CAST "qual"))
206 WRBUF wrbuf = wrbuf_alloc();
207 int r = ccl_xml_config_qual(bibset, set,
208 wrbuf, c_ptr, addinfo);
209 wrbuf_destroy(wrbuf);
213 else if (!xmlStrcmp(c_ptr->name, BAD_CAST "directive"))
215 int r = ccl_xml_config_directive(bibset, c_ptr, addinfo);
221 *addinfo = "bad element for 'cclmap'. "
222 "expecting 'directive' or 'qual'";
235 * c-file-style: "Stroustrup"
236 * indent-tabs-mode: nil
238 * vim: shiftwidth=4 tabstop=8 expandtab