void XMLElement::walkTree(Log::ModuleId logModule, Log::Level level, unsigned int depth, XMLElement node) { #ifdef PUGIXML xml_tree_walker walker(logModule, level); node.nodePtr.traverse(walker); #else while (node.isValid()) { XMLElement::Type nodeType = node.getType(); XMLAttribute attr; xmlChar *value; if (XMLElement::ELEMENT_NODE == nodeType) { if (node.nodePtr->name) { Log::log(logModule, level, "Element = %s", node.nodePtr->name); } else { Log::log(logModule, level, "Element, unnamed"); } for (attr = node.getFirstAttribute(); attr.isValid(); attr.next()) { attr.log(logModule, level, depth); } walkTree(logModule, level, depth + 1, node.getFirstSubElement()); } else if (XMLElement::CDATA_NODE == nodeType) { value = xmlNodeGetContent(node.nodePtr); if (value) { Log::log(logModule, level, "CDATA = '%s'", value); xmlFree(value); } else { Log::log(logModule, level, "CDATA unable to retrieve value"); } } else if (XMLElement::TEXT_NODE == nodeType) { value = xmlNodeGetContent(node.nodePtr); if (value) { Log::log(logModule, level, "TEXT = '%s'", value); xmlFree(value); } else { Log::log(logModule, level, "TEXT unable to retrieve value"); } } else { value = xmlNodeGetContent(node.nodePtr); if (value) { Log::log(logModule, level, "Type = %d, value = %s", nodeType, value); xmlFree(value); } else { Log::log(logModule, level, "Type = %d, unable to retrieve value", nodeType); } } node.nextSibling(); } #endif }
void XMLElement::walkTree(Log::ModuleId logModule, Log::Level level, unsigned int depth, XMLElement node) { while (node.isValid()) { XMLElement::Type nodeType = node.getType(); XMLAttribute attr; if (XMLElement::ELEMENT_NODE == nodeType) { std::string name; if (node.getName(name)) { Log::log(logModule, level, "Element = %s", name.c_str()); } else { Log::log(logModule, level, "Element, unnamed"); } for (attr = node.getFirstAttribute(); attr.isValid(); attr.next()) { attr.log(logModule, level, depth); } walkTree(logModule, level, depth + 1, node.getFirstSubElement()); } else if (XMLElement::CDATA_NODE == nodeType) { std::string value; if (node.getValue(value)) { Log::log(logModule, level, "CDATA = '%s'", value.c_str()); } else { Log::log(logModule, level, "CDATA unable to retrieve value"); } } else if (XMLElement::TEXT_NODE == nodeType) { std::string value; if (node.getValue(value)) { Log::log(logModule, level, "TEXT = '%s'", value.c_str()); } else { Log::log(logModule, level, "TEXT unable to retrieve value"); } } else { Log::log(logModule, level, "Type = %d, unknown node type", nodeType); } node.nextSibling(); } }