struct node const * xmlelement (struct node const * node, char const * name) { if (node) { node = node->below; } while (node) { if (node->type == NODE_ELEM) { struct node const * temp; if (!strcmp (node->text, name)) { break; } temp = xmlelement (node, name); if (temp) { return (temp); } } node=node->after; } return (node); }
char const * xmlselect (NODE * node, char const * element, char const * attribute) { node = xmlelement (node, element); if ((attribute) && (* attribute)) { node = xmlattribute (node, attribute); node = xmlvalue (node); } else { node = xmlcontent (node); } return (node? node->text: ""); }
bool xmlelement::subparse(std::ifstream& stream) { bool complete = false; while (!complete && stream) { subelements.push_back(xmlelement()); if (!subelements.back().parse(stream,true)) { throw xmlerror(std::string("Unexplained error")); } if (subelements.back().closetag) { if (subelements.back().name == name) { subelements.pop_back(); complete = true; } else { throw xmlerror(std::string("Element <") + name + std::string("> closed with </") + subelements.back().name + std::string(">")); } } } if (!complete) { throw xmlerror(std::string("Unexpected end of element ") + name); } return true; }