def export(self, filename): out = open(filename, "w") xmi = XMLWriter(out) attributes = { "xmi.version": self.XMI_VERSION, "xmlns:xmi": self.XMI_NAMESPACE, "xmlns:UML": self.UML_NAMESPACE, } xmi.startElement("XMI", attrs=attributes) for package in self.element_factory.select(self.select_package): self.handle(xmi, package) for generalization in self.element_factory.select( self.select_generalization): self.handle(xmi, generalization) for realization in self.element_factory.select( self.select_realization): self.handle(xmi, realization) xmi.endElement("XMI") logger.debug(self.handled_ids)
def test_elements_1(): w = Writer() xml_w = XMLWriter(w) xml_w.startDocument() xml_w.startElement("foo", {}) xml_w.endElement("foo") xml = """<?xml version="1.0" encoding="%s"?>\n<foo/>""" % sys.getdefaultencoding( ) assert w.s == xml, w.s + " != " + xml
def test_elements_2(): w = Writer() xml_w = XMLWriter(w) xml_w.startDocument() xml_w.startElement("foo", {}) xml_w.startElement("bar", {}) xml_w.endElement("bar") xml_w.endElement("foo") xml = ("""<?xml version="1.0" encoding="%s"?>\n<foo>\n<bar/>\n</foo>""" % sys.getdefaultencoding()) assert w.s == xml, w.s