示例#1
0
文件: tmxlib.py 项目: FrITA/frita
    def create_document(self):
        """uses xml.dom to create document with correct doctype"""
        dom = xml.dom.getDOMImplementation()
        tmxdoctype = dom.createDocumentType("tmx", None, "tmx14.dtd")
        tmx = dom.createDocument("http://www.lisa.org/tmx14", "tmx", tmxdoctype )

        return tmx
示例#2
0
    def create_document(self):
        """uses xml.dom to create document with correct doctype"""
        dom = xml.dom.getDOMImplementation()
        tmxdoctype = dom.createDocumentType("tmx", None, "tmx14.dtd")
        tmx = dom.createDocument("http://www.lisa.org/tmx14", "tmx",
                                 tmxdoctype)

        return tmx
示例#3
0
    def Save(self, ProjPath, Backup=False):
        """Save project in XML-project file"""

        # simple DOM realisation
        dom = xml.dom.minidom.getDOMImplementation()

        # "Game" - is root element
        # "IGv1" means that XML document is Instead Game of version 1
        DocType = dom.createDocumentType("IGv1", None, None)
        tree = dom.createDocument(None, "Game", DocType)
        root = tree.documentElement

        # saving settings
        Settings = tree.createElement("Settings")
        Settings.setAttribute("Name", self.Game.Settings["Name"])
        Settings.setAttribute("Version", self.Game.Settings["Version"])
        Settings.setAttribute("Author", self.Game.Settings["Author"])
        Settings.setAttribute("Description", self.Game.Settings["Description"])
        root.appendChild(Settings)

        # Game Items section
        Items = tree.createElement("Items")
        root.appendChild(Items)

        # xml element presenting Item looks like this
        # <Item Type="Scene" Name="house">text of the scene</Item>
        temp = ((SCENE, "Scene"), (XSCENE, "XScene"), (OBJECT, "Object"), (DIALOG, "Dialog"), (FUNCTION, "Function"))
        for i in range(len(temp)):
            for name in self.Game.GetNames(temp[i][0], True, True):
                element = tree.createElement("Item")
                element.setAttribute("Type", temp[i][1])
                element.setAttribute("Name", name)

                Code = self.Game.GetCode(name)
                if Code == "":
                    # Empty text data is not allowed in XML!
                    Code = " "

                code = tree.createTextNode(Code)
                element.appendChild(code)
                Items.appendChild(element)

        # make backup
        if Backup:
            try:
                shutil.copyfile(ProjPath, ProjPath + "~")
            except:
                pass

        # writing project file
        file = open(ProjPath, "tw+", encoding="utf-8")
        # xml_code = tree.toprettyxml(indent = " "*8)
        # print(xml_code)
        xml_code = tree.toxml()
        file.write(xml_code)
示例#4
0
 def createDocElementFromName(self, docname, dtd_filename):
     dom = xml.dom.minidom.getDOMImplementation()
     type = dom.createDocumentType(docname, None, dtd_filename)
     doc = dom.createDocument(None, docname, type)
     return doc