string AimlWriter::recurse(PElement element) { if (element == NULL) return ""; string s = ""; PElement child = element->getChild(); while (child != NULL) { if (child->getTagname() == "#text") { s += child->getText(false); } else if (child->getTagname() == "#cdata") { s += child->getText(false); } else { string tag = "<"; if (child->hasNamespace()) tag += child->getNamespace() + ":"; tag += child->getTagname(); if (child->hasAttributes()) { map<string, string> attr = child->getAttributes(); map<string, string>::const_iterator itr = attr.begin(); while (itr != attr.end()) { tag += " " + (*itr).first + "=\"" + (*itr).second + "\""; itr++; } } if (child->hasChildren()) { tag += ">" + recurse(child) + "</"; if (child->hasNamespace()) tag += child->getNamespace() + ":"; tag += child->getTagname() + ">"; } else { tag += "/>"; } s += tag; } child = child->getNextSibling(); } return s; }
string templateString(PElement element) { if (element == NULL) { return ""; } string result; PElement child = element->getChild(); while (child != NULL) { if (child->getTagname() == "#text") { result += child->getText(); } else if (child->getTagname() == "#cdata") { result += child->getText(false); } else { string tag = "<"; if (child->hasNamespace()) { tag += child->getNamespace() + ":"; } tag += child->getTagname(); if (child->hasAttributes()) { map<string, string> attr = child->getAttributes(); map<string, string>::const_iterator itr = attr.begin(); while (itr != attr.end()) { tag += " " + (*itr).first + "=\"" + (*itr).second + "\""; itr++; } } if (child->hasChildren()) { tag += ">" + templateString(child); tag += "</"; if (child->hasNamespace()) { tag += child->getNamespace() + ":"; } tag += child->getTagname() + ">"; } else { tag += "/>"; } result += tag; } child = child->getNextSibling(); } return result; }