2 * Copyright (C) 1995-2007, Index Data ApS
5 * $Id: cclxmlconfig.c,v 1.1 2007-01-08 13:20:58 adam Exp $
8 /** \file cclxmlconfig.c
9 \brief XML configuration for CCL
16 #include <yaz/ccl_xml.h>
20 static int ccl_xml_config_attr(CCL_bibset bibset, const char *default_set,
25 struct _xmlAttr *attr;
27 const char *value = 0;
28 const char *attrset = default_set;
29 for (attr = ptr->properties; attr; attr = attr->next)
31 if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
32 attr->children && attr->children->type == XML_TEXT_NODE)
33 type = (const char *) attr->children->content;
34 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
35 attr->children && attr->children->type == XML_TEXT_NODE)
36 value = (const char *) attr->children->content;
37 else if (!xmlStrcmp(attr->name, BAD_CAST "attrset") &&
38 attr->children && attr->children->type == XML_TEXT_NODE)
39 attrset = (const char *) attr->children->content;
42 *addinfo = "bad attribute for 'attr'. "
43 "Expecting 'type', 'value', or 'attrset'";
49 *addinfo = "missing attribute for 'type' for element 'attr'";
54 *addinfo = "missing attribute for 'value' for element 'attr'";
58 wrbuf_printf(wrbuf, "%s,%s=%s", attrset, type, value);
60 wrbuf_printf(wrbuf, "%s=%s", type, value);
64 static int ccl_xml_config_qual(CCL_bibset bibset, const char *default_set,
69 struct _xmlAttr *attr;
71 const xmlNode *a_ptr = ptr->children;
72 for (attr = ptr->properties; attr; attr = attr->next)
74 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
75 attr->children && attr->children->type == XML_TEXT_NODE)
76 name = (const char *) attr->children->content;
79 *addinfo = "bad attribute for 'qual'. Expecting 'name' only";
85 *addinfo = "missing attribute 'name' for 'qual' element";
88 for (; a_ptr; a_ptr = a_ptr->next)
90 if (a_ptr->type == XML_ELEMENT_NODE)
92 if (!xmlStrcmp(a_ptr->name, BAD_CAST "attr"))
94 int r = ccl_xml_config_attr(bibset, default_set, wrbuf,
98 wrbuf_printf(wrbuf, " ");
102 *addinfo = "bad element: expecting 'attr'";
107 ccl_qual_fitem(bibset, wrbuf_cstr(wrbuf), name);
111 int ccl_xml_config_directive(CCL_bibset bibset, const xmlNode *ptr,
112 const char **addinfo)
114 struct _xmlAttr *attr;
115 const char *name = 0;
116 const char *value = 0;
117 for (attr = ptr->properties; attr; attr = attr->next)
119 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
120 attr->children && attr->children->type == XML_TEXT_NODE)
121 name = (const char *) attr->children->content;
122 else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
123 attr->children && attr->children->type == XML_TEXT_NODE)
124 value = (const char *) attr->children->content;
127 *addinfo = "bad attribute for 'diretive'. "
128 "Expecting 'name' or 'value'";
134 *addinfo = "missing attribute 'name' for 'directive' element";
139 *addinfo = "missing attribute 'name' for 'value' element";
142 ccl_qual_add_special(bibset, name, value);
146 int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, const char **addinfo)
148 if (ptr && ptr->type == XML_ELEMENT_NODE &&
149 !xmlStrcmp(ptr->name, BAD_CAST "cclmap"))
151 const xmlNode *c_ptr;
153 struct _xmlAttr *attr;
154 for (attr = ptr->properties; attr; attr = attr->next)
156 if (!xmlStrcmp(attr->name, BAD_CAST "defaultattrset") &&
157 attr->children && attr->children->type == XML_TEXT_NODE)
158 set = (const char *) attr->children->content;
161 *addinfo = "bad attribute for 'cclmap'. "
162 "expecting 'defaultattrset'";
166 for (c_ptr = ptr->children; c_ptr; c_ptr = c_ptr->next)
168 if (c_ptr->type == XML_ELEMENT_NODE)
170 if (!xmlStrcmp(c_ptr->name, BAD_CAST "qual"))
172 WRBUF wrbuf = wrbuf_alloc();
173 int r = ccl_xml_config_qual(bibset, set,
174 wrbuf, c_ptr, addinfo);
175 wrbuf_destroy(wrbuf);
179 else if (!xmlStrcmp(c_ptr->name, BAD_CAST "directive"))
181 int r = ccl_xml_config_directive(bibset, c_ptr, addinfo);
187 *addinfo = "bad element for 'cclmap'. "
188 "expecting 'directive' or 'qual'";
197 int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, const char **addinfo)
199 *addinfo = "CCL XML configuration not supported. Libxml2 is disabled";
207 * indent-tabs-mode: nil
209 * vim: shiftwidth=4 tabstop=8 expandtab