X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FTDocument.cc;h=e578b79f46ae9d8411f3d00931c8c5dcbacac2e1;hb=387aeebf96181c051b7f527a0901b173cfcdf194;hp=a7b5c8d3a5d2cb57fcd5adc11f79eb6e61ad91ab;hpb=2f94240bc382ca43017f31b0852f1717fe18090b;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/TDocument.cc b/helm/DEVEL/mathml_editor/src/TDocument.cc index a7b5c8d3a..e578b79f4 100644 --- a/helm/DEVEL/mathml_editor/src/TDocument.cc +++ b/helm/DEVEL/mathml_editor/src/TDocument.cc @@ -34,16 +34,19 @@ TDocument::serialize(const char* filename) const di.saveDocumentToFile(doc, filename, GDOME_SAVE_LIBXML_INDENT); } +std::string +TDocument::makeId(unsigned id) +{ + ostringstream os; + os << "I" << id; + return os.str(); +} + TNode TDocument::create(const std::string& name, unsigned id) const { DOM::Element elem = doc.createElementNS(TML_NS_URI, "tml:" + name); - if (id > 0) - { - ostringstream os; - os << "I" << id; - elem.setAttribute("id", os.str()); - } + if (id > 0) elem.setAttribute("id", makeId(id)); return elem; } @@ -130,6 +133,24 @@ TDocument::findIdNode(const DOM::Node& node) return DOM::Node(0); } +TNode +TDocument::getNodeByIdAux(const TNode& node, const std::string& id) +{ + if (node.hasId(id)) return node; + else + for (TNode p = node.first(); p; p = p.next()) + if (TNode res = getNodeByIdAux(p, id)) return res; + return TNode(); +} + +TNode +TDocument::getNodeById(unsigned id) const +{ + DOM::Element root = doc.get_documentElement(); + assert(root); + return getNodeByIdAux(root, makeId(id)); +} + void TDocument::handleEvent(const DOM::Event& ev) {