void writeSiblingsXML(const tree<AstNode>& t, const tree<AstNode>::iterator iRoot, ostream& stream) { if(t.empty()) return; if (iRoot->getType() == "root") { tree<AstNode>::sibling_iterator iChildren = t.begin(iRoot); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl; writeSiblingsXML(t,iChildren,stream); } else if (t.number_of_children(iRoot) == 0) { string type = iRoot->getType(); stream << "<php:" << type << '>'; if (iRoot->getValue().length() > 0) stream << htmlentities(iRoot->getValue()); stream << "</php:" << type << '>' << endl; } else { string type = iRoot->getType(); string xmlns=""; if (type == "start") xmlns = " xmlns:php=\"http://php.net/csl\""; stream << "<php:" << type << xmlns << '>' << endl; int siblingNum; tree<AstNode>::sibling_iterator iChildren; for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren) { writeSiblingsXML(t,iChildren,stream); } stream << "</php:" << type << '>' << endl; } }
/** Insert a new statement. - Create a new inner_statement_list - Add the statement under it */ bool insert_statement(const tree<AstNode>::iterator& where, const tree<AstNode>::iterator& what, tree<AstNode>& tr) { if (where->getType() == "text" && where->getValue() == "$enter_the_new_statement") { // rewind to the inner_statement_list tree<AstNode>::iterator top = where; do { top = tr.parent(top); } while (top->getType() != "inner_statement" && tr.child(top,0)->getType() != "statement"); top = tr.parent(top); if (top->getType() != "inner_statement_list") return false; else { top = tr.append_child(top, AstNode("inner_statement_list")); top = tr.append_child(top, AstNode("inner_statement")); if (what->getType() == "statement") { top = tr.append_child(top, AstNode("statement")); //cout << "Seems to be okay..." << endl; move_branch(top, what, tr); } } return true; } return false; }