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_attr(CCL_bibset bibset, const char *default_set,
23 struct _xmlAttr *attr;
25 const char *value = 0;
26 const char *attrset = default_set;
27 for (attr = ptr->properties; attr; attr = attr->next)
29 if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
30 attr->children && attr->children->type == XML_TEXT_NODE)
31 type = (const char *) attr->children->content;
32 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
33 attr->children && attr->children->type == XML_TEXT_NODE)
34 value = (const char *) attr->children->content;
35 else if (!xmlStrcmp(attr->name, BAD_CAST "attrset") &&
36 attr->children && attr->children->type == XML_TEXT_NODE)
37 attrset = (const char *) attr->children->content;
40 *addinfo = "bad attribute for 'attr'. "
41 "Expecting 'type', 'value', or 'attrset'";
47 *addinfo = "missing attribute for 'type' for element 'attr'";
52 *addinfo = "missing attribute for 'value' for element 'attr'";
56 wrbuf_printf(wrbuf, "%s,%s=%s", attrset, type, value);
58 wrbuf_printf(wrbuf, "%s=%s", type, value);
62 static int ccl_xml_config_qual(CCL_bibset bibset, const char *default_set,
67 struct _xmlAttr *attr;
69 const xmlNode *a_ptr = ptr->children;
70 for (attr = ptr->properties; attr; attr = attr->next)
72 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
73 attr->children && attr->children->type == XML_TEXT_NODE)
74 name = (const char *) attr->children->content;
77 *addinfo = "bad attribute for 'qual'. Expecting 'name' only";
83 *addinfo = "missing attribute 'name' for 'qual' element";
86 for (; a_ptr; a_ptr = a_ptr->next)
88 if (a_ptr->type == XML_ELEMENT_NODE)
90 if (!xmlStrcmp(a_ptr->name, BAD_CAST "attr"))
92 int r = ccl_xml_config_attr(bibset, default_set, wrbuf,
96 wrbuf_printf(wrbuf, " ");
100 *addinfo = "bad element: expecting 'attr'";
105 ccl_qual_fitem(bibset, wrbuf_cstr(wrbuf), name);
109 int ccl_xml_config_directive(CCL_bibset bibset, const xmlNode *ptr,
110 const char **addinfo)
112 struct _xmlAttr *attr;
113 const char *name = 0;
114 const char *value = 0;
115 for (attr = ptr->properties; attr; attr = attr->next)
117 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
118 attr->children && attr->children->type == XML_TEXT_NODE)
119 name = (const char *) attr->children->content;
120 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
121 attr->children && attr->children->type == XML_TEXT_NODE)
122 value = (const char *) attr->children->content;
125 *addinfo = "bad attribute for 'diretive'. "
126 "Expecting 'name' or 'value'";
132 *addinfo = "missing attribute 'name' for 'directive' element";
137 *addinfo = "missing attribute 'name' for 'value' element";
140 ccl_qual_add_special(bibset, name, value);
144 int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, const char **addinfo)
146 if (ptr && ptr->type == XML_ELEMENT_NODE &&
147 !xmlStrcmp(ptr->name, BAD_CAST "cclmap"))
149 const xmlNode *c_ptr;
151 struct _xmlAttr *attr;
152 for (attr = ptr->properties; attr; attr = attr->next)
154 if (!xmlStrcmp(attr->name, BAD_CAST "defaultattrset") &&
155 attr->children && attr->children->type == XML_TEXT_NODE)
156 set = (const char *) attr->children->content;
159 *addinfo = "bad attribute for 'cclmap'. "
160 "expecting 'defaultattrset'";
164 for (c_ptr = ptr->children; c_ptr; c_ptr = c_ptr->next)
166 if (c_ptr->type == XML_ELEMENT_NODE)
168 if (!xmlStrcmp(c_ptr->name, BAD_CAST "qual"))
170 WRBUF wrbuf = wrbuf_alloc();
171 int r = ccl_xml_config_qual(bibset, set,
172 wrbuf, c_ptr, addinfo);
173 wrbuf_destroy(wrbuf);
177 else if (!xmlStrcmp(c_ptr->name, BAD_CAST "directive"))
179 int r = ccl_xml_config_directive(bibset, c_ptr, addinfo);
185 *addinfo = "bad element for 'cclmap'. "
186 "expecting 'directive' or 'qual'";
199 * c-file-style: "Stroustrup"
200 * indent-tabs-mode: nil
202 * vim: shiftwidth=4 tabstop=8 expandtab