17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
26 int *error_code,
const char **addinfo)
28 if (ptr && ptr->type == XML_ELEMENT_NODE &&
29 !xmlStrcmp(ptr->name, BAD_CAST
"diagnostic"))
31 struct _xmlAttr *attr;
32 const char *code_str = 0;
33 const char *addinfo_str = 0;
34 for (attr = ptr->properties; attr; attr = attr->next)
36 if (!xmlStrcmp(attr->name, BAD_CAST
"code") &&
37 attr->children && attr->children->type == XML_TEXT_NODE)
38 code_str = (
const char *) attr->children->content;
39 else if (!xmlStrcmp(attr->name, BAD_CAST
"addinfo") &&
40 attr->children && attr->children->type == XML_TEXT_NODE)
41 addinfo_str = (
const char *) attr->children->content;
45 *addinfo =
"bad attribute for diagnostic element";
52 *addinfo =
"missing @code for diagnostic element";
55 *error_code = atoi(code_str);
68 const char *setname = 0;
79 xmlNodePtr
node = xmlNewChild(parent, 0, BAD_CAST
"attr", 0);
82 xmlNewProp(node, BAD_CAST
"set", BAD_CAST setname);
86 xmlNewProp(node, BAD_CAST
"type", BAD_CAST formstr);
89 xmlNewProp(node, BAD_CAST
"value", BAD_CAST formstr);
96 xmlNodePtr
node = xmlNewChild(parent, 0, BAD_CAST
"attr", 0);
99 xmlNewProp(node, BAD_CAST
"set", BAD_CAST setname);
102 xmlNewProp(node, BAD_CAST
"type", BAD_CAST formstr);
107 xmlNewProp(node, BAD_CAST
"value", BAD_CAST
115 xmlNewProp(node, BAD_CAST
"value", BAD_CAST formstr);
125 xmlNodePtr
node = xmlNewChild(parent, 0, BAD_CAST
"term", 0);
127 const char *
type = 0;
138 t = xmlNewText(BAD_CAST formstr);
154 type =
"integerAndUnit";
163 xmlAddChild(node, t);
165 xmlNewProp(node, BAD_CAST
"type", BAD_CAST type);
172 xmlNodePtr
node = xmlNewChild(parent, 0, BAD_CAST
"apt", 0);
175 for (i = 0; i<num_attributes; i++)
185 const char *
type = 0;
203 xmlNewProp(node, BAD_CAST
"type", BAD_CAST type);
212 xmlNewProp(node, BAD_CAST
"exclusion", BAD_CAST
"true");
214 xmlNewProp(node, BAD_CAST
"exclusion", BAD_CAST
"false");
217 xmlNewProp(node, BAD_CAST
"distance", BAD_CAST formstr);
220 xmlNewProp(node, BAD_CAST
"ordered", BAD_CAST
"true");
222 xmlNewProp(node, BAD_CAST
"ordered", BAD_CAST
"false");
225 xmlNewProp(node, BAD_CAST
"relationType", BAD_CAST formstr);
231 xmlNewProp(node, BAD_CAST
"knownProximityUnit",
236 xmlNewProp(node, BAD_CAST
"privateProximityUnit",
250 xmlNodePtr
node = xmlNewChild(parent, 0, BAD_CAST
"operator", 0);
263 return xmlNewChild(parent, 0, BAD_CAST
"rset",
277 xmlNewProp(parent, BAD_CAST
"set", BAD_CAST setname);
308 xmlNodePtr top_node, q_node = 0, child_node = 0;
313 top_node = xmlNewNode(0, BAD_CAST
"query");
319 q_node = xmlNewChild(top_node, 0, BAD_CAST
"rpn", 0);
323 q_node = xmlNewChild(top_node, 0, BAD_CAST
"ccl", 0);
327 q_node = xmlNewChild(top_node, 0, BAD_CAST
"z39.58", 0);
333 q_node = xmlNewChild(top_node, 0, BAD_CAST
"cql", 0);
337 if (child_node && q_node)
339 *docp = xmlNewDoc(BAD_CAST
"1.0");
340 xmlDocSetRootElement(*docp, top_node);
345 xmlFreeNode(top_node);
351 if (*str ==
'\0' || strchr(
"0fF", *str))
363 int *error_code,
const char **addinfo)
365 xmlChar *
type = xmlGetProp((xmlNodePtr) ptr, BAD_CAST
"type");
369 *addinfo =
"no operator type";
373 if (!xmlStrcmp(type, BAD_CAST
"and"))
378 else if (!xmlStrcmp(type, BAD_CAST
"or"))
383 else if (!xmlStrcmp(type, BAD_CAST
"not"))
388 else if (!xmlStrcmp(type, BAD_CAST
"prox"))
390 struct _xmlAttr *attr;
404 for (attr = ptr->properties; attr; attr = attr->next)
406 const char *value = (
const char *) attr->children->content;
407 if (!xmlStrcmp(attr->name, BAD_CAST
"type"))
409 else if (!xmlStrcmp(attr->name, BAD_CAST
"exclusion"))
411 else if (!xmlStrcmp(attr->name, BAD_CAST
"distance"))
413 else if (!xmlStrcmp(attr->name, BAD_CAST
"ordered"))
415 else if (!xmlStrcmp(attr->name, BAD_CAST
"relationType"))
417 else if (!xmlStrcmp(attr->name, BAD_CAST
"knownProximityUnit"))
422 else if (!xmlStrcmp(attr->name, BAD_CAST
"privateProximityUnit"))
430 *addinfo =
"bad proximity attribute";
438 *addinfo =
"bad operator type";
446 const char **addinfo)
453 struct _xmlAttr *attr;
454 for (attr = ptr->properties; attr; attr = attr->next)
456 if (!xmlStrcmp(attr->name, BAD_CAST
"set") &&
457 attr->children && attr->children->type == XML_TEXT_NODE)
458 set = attr->children->content;
459 else if (!xmlStrcmp(attr->name, BAD_CAST
"type") &&
460 attr->children && attr->children->type == XML_TEXT_NODE)
461 type = attr->children->content;
462 else if (!xmlStrcmp(attr->name, BAD_CAST
"value") &&
463 attr->children && attr->children->type == XML_TEXT_NODE)
465 value = attr->children->content;
471 *addinfo =
"bad attribute for attr content";
478 *addinfo =
"missing type attribute for att content";
484 *addinfo =
"missing value attribute for att content";
495 (*elem)->attributeSet = 0;
496 (*elem)->attributeType =
intVal(odr, (
const char *) type);
499 for (i = 0; value[i] && value[i] >=
'0' && value[i] <=
'9'; i++)
501 if (num_values > 1 || value[i])
504 (*elem)->value.complex =
506 (*elem)->value.complex->num_list = num_values;
512 for (attr = ptr->properties; attr; attr = attr->next)
514 if (!xmlStrcmp(attr->name, BAD_CAST
"value") &&
515 attr->children && attr->children->type == XML_TEXT_NODE)
517 const char *val = (
const char *) attr->children->content;
518 assert (i < num_values);
521 (*elem)->value.complex->list[i]->which =
523 (*elem)->value.complex->list[i]->u.string =
528 (*elem)->value.complex->num_semanticAction = 0;
529 (*elem)->value.complex->semanticAction = 0;
534 (*elem)->value.numeric =
intVal(odr, (
const char *) value);
544 int *error_code,
const char **addinfo)
547 struct _xmlAttr *attr;
548 char *cdata =
strVal(ptr->children, odr);
550 for (attr = ptr->properties; attr; attr = attr->next)
552 if (!xmlStrcmp(attr->name, BAD_CAST
"type") &&
553 attr->children && attr->children->type == XML_TEXT_NODE)
554 type = attr->children->content;
558 *addinfo =
"bad attribute for attr content";
564 if (!type || !xmlStrcmp(type, BAD_CAST
"general"))
570 else if (!xmlStrcmp(type, BAD_CAST
"numeric"))
573 (*term)->u.numeric =
intVal(odr, cdata);
575 else if (!xmlStrcmp(type, BAD_CAST
"string"))
578 (*term)->u.characterString = cdata;
580 else if (!xmlStrcmp(type, BAD_CAST
"oid"))
583 *addinfo =
"unhandled term type: oid";
585 else if (!xmlStrcmp(type, BAD_CAST
"dateTime"))
588 *addinfo =
"unhandled term type: dateTime";
590 else if (!xmlStrcmp(type, BAD_CAST
"integerAndUnit"))
593 *addinfo =
"unhandled term type: integerAndUnit";
595 else if (!xmlStrcmp(type, BAD_CAST
"null"))
603 *addinfo =
"unhandled term type";
609 int *error_code,
const char **addinfo)
611 const xmlNode *ptr = ptr_apt->children;
622 for (; ptr; ptr = ptr->next)
623 if (ptr->type == XML_ELEMENT_NODE)
625 if (!xmlStrcmp(ptr->name, BAD_CAST
"attr"))
632 (*zapt)->attributes->num_attributes = num_attr;
637 ptr = ptr_apt->children;
638 for (; ptr; ptr = ptr->next)
639 if (ptr->type == XML_ELEMENT_NODE)
641 if (!xmlStrcmp(ptr->name, BAD_CAST
"attr"))
644 ptr, &(*zapt)->attributes->attributes[i], odr,
645 error_code, addinfo);
654 if (ptr && ptr->type == XML_ELEMENT_NODE)
656 if (!xmlStrcmp(ptr->name, BAD_CAST
"term"))
664 *addinfo =
"bad element in apt content";
670 *addinfo =
"missing term node in apt content";
675 ODR odr,
int *error_code,
const char **addinfo)
679 *rset =
strVal(ptr->children, odr);
684 *addinfo =
"missing rset content";
690 int *error_code,
const char **addinfo)
692 while (ptr && ptr->type != XML_ELEMENT_NODE)
695 if (!ptr || ptr->type != XML_ELEMENT_NODE)
698 *addinfo =
"missing rpn operator, rset, apt node";
705 if (!xmlStrcmp(ptr->name, BAD_CAST
"operator"))
710 (*zs)->u.complex = zc;
715 while (ptr && ptr->type != XML_ELEMENT_NODE)
720 while (ptr && ptr->type != XML_ELEMENT_NODE)
729 if (!xmlStrcmp(ptr->name, BAD_CAST
"apt"))
733 odr, error_code, addinfo);
735 else if (!xmlStrcmp(ptr->name, BAD_CAST
"rset"))
739 odr, error_code, addinfo);
744 *addinfo =
"bad element: expected binary, apt or rset";
750 int *error_code,
const char **addinfo)
752 xmlChar *
set = xmlGetProp((xmlNodePtr) ptr, BAD_CAST
"set");
757 (*query)->attributeSetId =
763 (*query)->attributeSetId = 0;
765 odr, error_code, addinfo);
769 int *error_code,
const char **addinfo)
773 if (ptr && ptr->type == XML_ELEMENT_NODE &&
774 !xmlStrcmp(ptr->name, BAD_CAST
"query"))
778 while (ptr && ptr->type != XML_ELEMENT_NODE)
780 if (!ptr || ptr->type != XML_ELEMENT_NODE)
783 *addinfo =
"missing query content";
786 type = (
const char *) ptr->name;
789 if (!type || !strcmp(type,
"rpn"))
793 error_code, addinfo);
795 else if (!strcmp(type,
"ccl"))
798 *addinfo =
"ccl not supported yet";
800 else if (!strcmp(type,
"z39.58"))
803 *addinfo =
"z39.58 not supported yet";
805 else if (!strcmp(type,
"cql"))
808 *addinfo =
"cql not supported yet";
813 *addinfo =
"unsupported query type";
819 *addinfo =
"missing query element";
824 int *error_code,
const char **addinfo)