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 IrcResponder::respond(Match *m, PElement element, const string &id) { if (element->getNamespace() != "irc") { return ""; } else { string tag = element->getTagname(); if (tag == "channel") { return mChannel; } else if (tag == "nick") { return mNick; } else if (tag == "command") { string cmd = Kernel::process(m, element, this, id); if (cmd[0] == '/') { processAlias(cmd); } else { q.push(cmd); } } else if (tag == "exit") { disconnect(); serverRunning = false; // Natural quit } else { cout << "<irc:" << tag << "> not supported" << endl; } } return ""; }
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; }