6 #include "TDocument.hh"
10 DOM::DOMImplementation di;
12 doc = di.createDocument(TML_NS_URI, "tml:tex", dt);
13 DOM::Element root = doc.get_documentElement();
14 root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI);
17 DOM::EventTarget et(doc);
19 et.addEventListener("DOMSubtreeModified", *this, false);
22 TDocument::~TDocument()
24 //DOM::Element root = doc.get_documentElement();
25 DOM::EventTarget et(doc);
27 et.removeEventListener("DOMSubtreeModified", *this, false);
31 TDocument::serialize(const char* filename) const
33 DOM::DOMImplementation di;
34 di.saveDocumentToFile(doc, filename, GDOME_SAVE_LIBXML_INDENT);
38 TDocument::create(const std::string& name, unsigned id) const
40 DOM::Element elem = doc.createElementNS(TML_NS_URI, "tml:" + name);
45 elem.setAttribute("id", os.str());
51 TDocument::createC(const std::string& name, unsigned id) const
53 TNode m = create("c", id);
59 TDocument::createT(const std::string& name, const std::string& text, unsigned id) const
61 TNode t = create(name, id);
67 TDocument::nodeDepth(const DOM::Node& node)
75 n = n.get_parentNode();
81 TDocument::findCommonAncestor(const DOM::Node& node1, const DOM::Node& node2)
86 unsigned d1 = nodeDepth(n1);
87 unsigned d2 = nodeDepth(n2);
89 cout << "finding common ancestor " << d1 << " " << d2 << endl;
94 n2 = n2.get_parentNode();
101 n1 = n1.get_parentNode();
109 n1 = n1.get_parentNode();
110 n2 = n2.get_parentNode();
117 TDocument::findIdNode(const DOM::Node& node)
122 if (n.get_nodeType() == DOM::Node::ELEMENT_NODE)
125 if (el.hasAttribute("id")) return el;
127 n = n.get_parentNode();
134 TDocument::handleEvent(const DOM::Event& ev)
136 DOM::MutationEvent me(ev);
140 cout << "TDocument::handleEvent DIRTY BEFORE = " << dirty.getAttribute("id") << endl;
142 cout << "TDocument::handleEvent DIRTY BEFORE = (nil)" << endl;
144 if (DOM::Node node = me.get_target())
146 dirty = findIdNode(findCommonAncestor(dirty, node));
148 dirty = findIdNode(node);
152 cout << "TDocument::handleEvent target = " << DOM::Node(me.get_target()).get_nodeName() << " DIRTY AFTER = "
153 << dirty.getAttribute("id") << " ME = " << DOM::Node(me.get_target()).get_nodeName() << endl;