1 /* $Id: xmlutil.cpp,v 1.8 2006-06-19 13:08:00 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
10 namespace mp = metaproxy_1;
11 // Doxygen doesn't like mp::xml, so we use this instead
12 namespace mp_xml = metaproxy_1::xml;
14 std::string mp_xml::get_text(const xmlNode *ptr)
17 for (ptr = ptr->children; ptr; ptr = ptr->next)
18 if (ptr->type == XML_TEXT_NODE)
19 c += std::string((const char *) (ptr->content));
23 bool mp_xml::get_bool(const xmlNode *ptr, bool default_value)
25 if (ptr && ptr->type == XML_TEXT_NODE && ptr->content)
27 if (!strcmp((const char *) ptr->content, "true"))
35 bool mp_xml::is_element(const xmlNode *ptr,
36 const std::string &ns,
37 const std::string &name)
39 if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href
40 && !xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href)
41 && !xmlStrcmp(BAD_CAST name.c_str(), ptr->name))
46 bool mp_xml::is_element_yp2(const xmlNode *ptr,
47 const std::string &name)
49 return mp::xml::is_element(ptr, "http://indexdata.dk/yp2/config/1", name);
53 bool mp_xml::check_element_yp2(const xmlNode *ptr,
54 const std::string &name)
56 if (!mp::xml::is_element_yp2(ptr, name))
57 throw mp::XMLError("Expected element name " + name);
61 std::string mp_xml::get_route(const xmlNode *node)
63 std::string route_value;
66 const struct _xmlAttr *attr;
67 for (attr = node->properties; attr; attr = attr->next)
69 std::string name = std::string((const char *) attr->name);
72 if (attr->children && attr->children->type == XML_TEXT_NODE)
73 value = std::string((const char *)attr->children->content);
78 throw XMLError("Only attribute route allowed"
79 " in " + std::string((const char *)node->name)
80 + " element. Got " + std::string(name));
87 const xmlNode* mp_xml::jump_to_children(const xmlNode* node,
90 node = node->children;
91 for (; node && node->type != xml_node_type; node = node->next)
96 const xmlNode* mp_xml::jump_to_next(const xmlNode* node,
100 for (; node && node->type != xml_node_type; node = node->next)
105 const xmlNode* mp_xml::jump_to(const xmlNode* node,
108 for (; node && node->type != xml_node_type; node = node->next)
113 void mp_xml::check_empty(const xmlNode *node)
118 for (n = node->children; n; n = n->next)
119 if (n->type == XML_ELEMENT_NODE)
120 throw mp::XMLError("No child elements allowed inside element "
121 + std::string((const char *) node->name));
128 * indent-tabs-mode: nil
129 * c-file-style: "stroustrup"
131 * vim: shiftwidth=4 tabstop=8 expandtab