// internal helper function to process elements void processXMLElement(XMLHandler& handler, xmlNode* node) { // build attributes block for the element XMLAttributes attrs; xmlAttrPtr currAttr = node->properties; while (currAttr) { xmlChar* val = xmlGetProp(node, currAttr->name); attrs.add((utf8*)currAttr->name, (utf8*)val); xmlFree(val); currAttr = currAttr->next; } // element start processing handler.elementStart((utf8*)node->name, attrs); for (xmlNode* cur_node = node->children; cur_node; cur_node = cur_node->next) { switch(cur_node->type) { case XML_ELEMENT_NODE: processXMLElement(handler, cur_node); break; case XML_TEXT_NODE: if (cur_node->content != 0 && *cur_node->content!= '\0') handler.text((utf8*)cur_node->content); break; } } // element end processing handler.elementEnd((utf8*)node->name); }
void Option::printHelpTOC(XMLHandler &handler, const string &prefix) const { handler.startElement("li"); XMLAttributes attrs; attrs["href"] = "#" + prefix + "option-" + getName(); handler.startElement("a", attrs); handler.text(getName()); handler.endElement("a"); handler.endElement("li"); }
void Option::printHelp(XMLHandler &handler, const string &prefix) const { XMLAttributes attrs; attrs["class"] = "option"; attrs["id"] = prefix + "option-" + getName(); handler.startElement("div", attrs); // Name attrs.clear(); attrs["class"] = "name"; handler.startElement("span", attrs); handler.text(getName()); handler.endElement("span"); // Type attrs["class"] = "type"; handler.startElement("span", attrs); handler.text(isOptional() ? "[" : "<"); handler.text(getTypeString()); // Default if (hasDefault()) { handler.text(" = "); bool isString = type == STRING_TYPE || type == STRINGS_TYPE; attrs["class"] = "default"; handler.startElement("span", attrs); handler.text((isString ? "\"" : "") + getDefault() + (isString ? "\"" : "")); handler.endElement("span"); } handler.text(isOptional() ? "]" : ">"); handler.endElement("span"); // Help if (getHelp() != "") { attrs["class"] = "help"; handler.startElement("div", attrs); string help = getHelp(); vector<string> tokens; String::tokenize(help, tokens, "\t"); handler.text(String::join(tokens, " ")); handler.text(" "); handler.endElement("div"); } handler.endElement("div"); }
void Option::write(XMLHandler &handler, uint32_t flags) const { XMLAttributes attrs; string value = toString(); if (isObscured() && !(flags & OBSCURED_FLAG)) value = string(value.size(), '*'); if (!isPlural()) attrs["v"] = value; handler.startElement(name, attrs); if (isPlural()) handler.text(value); handler.endElement(name); }
//----------------------------------------------------------------------------// void RapidXMLDocument::processElement(const rapidxml::xml_node<>* element) { // build attributes block for the element XMLAttributes attrs; rapidxml::xml_attribute<>* currAttr = element->first_attribute(0); while (currAttr) { attrs.add((utf8*)currAttr->name(), (utf8*)currAttr->value()); currAttr = currAttr->next_attribute(); } // start element d_handler->elementStart((utf8*)element->name(), attrs); // do children rapidxml::xml_node<>* childNode = element->first_node(); while (childNode) { switch (childNode->type()) { case rapidxml::node_element: processElement(childNode); break; case rapidxml::node_data: if (childNode->value() != '\0') d_handler->text((utf8*)childNode->value()); break; // Silently ignore unhandled node type }; childNode = childNode->next_sibling(); } // end element d_handler->elementEnd((utf8*)element->name()); }
void TinyXMLDocument::processElement(const TiXmlElement* element) { // build attributes block for the element XMLAttributes attrs; const TiXmlAttribute *currAttr = element->FirstAttribute(); while (currAttr) { attrs.add((encoded_char*)currAttr->Name(), (encoded_char*)currAttr->Value()); currAttr = currAttr->Next(); } // start element d_handler->elementStart((encoded_char*)element->Value(), attrs); // do children const TiXmlNode* childNode = element->FirstChild(); while (childNode) { switch(childNode->Type()) { case TiXmlNode::CEGUI_TINYXML_ELEMENT: processElement(childNode->ToElement()); break; case TiXmlNode::CEGUI_TINYXML_TEXT: if (childNode->ToText()->Value() != '\0') d_handler->text((encoded_char*)childNode->ToText()->Value()); break; // Silently ignore unhandled node type }; childNode = childNode->NextSibling(); } // end element d_handler->elementEnd((encoded_char*)element->Value()); }
void ExpatParser::characterData(void *data, const char *text, int len) { XMLHandler* handler = static_cast<XMLHandler*>(data); String str((const encoded_char*)text, static_cast<String::size_type>(len)); handler->text(str); }