1 /* $Id: xmlutil.cpp,v 1.5 2006-03-16 10:40:59 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
9 namespace mp = metaproxy_1;
11 std::string mp::xml::get_text(const xmlNode *ptr)
14 for (ptr = ptr->children; ptr; ptr = ptr->next)
15 if (ptr->type == XML_TEXT_NODE)
16 c += std::string((const char *) (ptr->content));
21 bool mp::xml::is_element(const xmlNode *ptr,
22 const std::string &ns,
23 const std::string &name)
25 if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href
26 && !xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href)
27 && !xmlStrcmp(BAD_CAST name.c_str(), ptr->name))
32 bool mp::xml::is_element_yp2(const xmlNode *ptr,
33 const std::string &name)
35 return mp::xml::is_element(ptr, "http://indexdata.dk/yp2/config/1", name);
39 bool mp::xml::check_element_yp2(const xmlNode *ptr,
40 const std::string &name)
42 if (!mp::xml::is_element_yp2(ptr, name))
43 throw mp::XMLError("Expected element name " + name);
47 std::string mp::xml::get_route(const xmlNode *node)
49 std::string route_value;
52 const struct _xmlAttr *attr;
53 for (attr = node->properties; attr; attr = attr->next)
55 std::string name = std::string((const char *) attr->name);
58 if (attr->children && attr->children->type == XML_TEXT_NODE)
59 value = std::string((const char *)attr->children->content);
64 throw XMLError("Only attribute route allowed"
65 " in " + std::string((const char *)node->name)
66 + " element. Got " + std::string(name));
73 const xmlNode* mp::xml::jump_to_children(const xmlNode* node,
76 node = node->children;
77 for (; node && node->type != xml_node_type; node = node->next)
82 const xmlNode* mp::xml::jump_to_next(const xmlNode* node,
86 for (; node && node->type != xml_node_type; node = node->next)
91 const xmlNode* mp::xml::jump_to(const xmlNode* node,
94 for (; node && node->type != xml_node_type; node = node->next)
99 void mp::xml::check_empty(const xmlNode *node)
104 for (n = node->children; n; n = n->next)
105 if (n->type == XML_ELEMENT_NODE)
106 throw mp::XMLError("No child elements allowed inside element "
107 + std::string((const char *) node->name));
114 * indent-tabs-mode: nil
115 * c-file-style: "stroustrup"
117 * vim: shiftwidth=4 tabstop=8 expandtab