当前位置: 首页>>代码示例>>Python>>正文


Python minidom.Document方法代码示例

本文整理汇总了Python中xml.dom.minidom.Document方法的典型用法代码示例。如果您正苦于以下问题:Python minidom.Document方法的具体用法?Python minidom.Document怎么用?Python minidom.Document使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.dom.minidom的用法示例。


在下文中一共展示了minidom.Document方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __init__(self,name,world=None):
        self.world = world
        self.actions = set()
        self.legal = {}
        self.omega = True
#        self.O = True
        self.models = {}
        self.modelList = {}
        self.x = None
        self.y = None
        self.color = None
        if isinstance(name,Document):
            self.parse(name.documentElement)
        elif isinstance(name,Node):
            self.parse(name)
        else:
            self.name = name
        self.parallel = False
        self.epsilon = 1e-6 
开发者ID:pynadath,项目名称:psychsim,代码行数:21,代码来源:agent.py

示例2: __xml__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __xml__(self):
        doc = Document()
        root = doc.createElement('V')
        doc.appendChild(root)
        for horizon in range(len(self.table)):
            subnode = doc.createElement('table')
            subnode.setAttribute('horizon',str(horizon))
            for state,V_s in self.table[horizon].items():
                subnode.appendChild(state.__xml__().documentElement)
                for name,V_s_a in V_s.items():
                    for action,V in V_s_a.items():
                        subsubnode = doc.createElement('value')
                        subsubnode.setAttribute('agent',name)
                        if action:
                            subsubnode.appendChild(action.__xml__().documentElement)
                        subsubnode.appendChild(doc.createTextNode(str(V)))
                        subnode.appendChild(subsubnode)
            root.appendChild(subnode)
        return doc 
开发者ID:pynadath,项目名称:psychsim,代码行数:21,代码来源:agent.py

示例3: __xml__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __xml__(self):
        doc = Document()
        root = doc.createElement('diagram')
        for key,value in self.x.items():
            node = doc.createElement('x')
            node.setAttribute('key',key)
            node.appendChild(doc.createTextNode(str(value)))
            root.appendChild(node)
        for key,value in self.y.items():
            node = doc.createElement('y')
            node.setAttribute('key',key)
            node.appendChild(doc.createTextNode(str(value)))
            root.appendChild(node)
        for key,value in self.color.items():
            node = doc.createElement('color')
            if key:
                node.setAttribute('key',key)
            node.appendChild(doc.createTextNode(str(value.name())))
            root.appendChild(node)
        doc.appendChild(root)
        return doc 
开发者ID:pynadath,项目名称:psychsim,代码行数:23,代码来源:diagram.py

示例4: testLegalChildren

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def testLegalChildren(self):
        dom = Document()
        elem = dom.createElement('element')
        text = dom.createTextNode('text')
        self.assertRaises(xml.dom.HierarchyRequestErr, dom.appendChild, text)

        dom.appendChild(elem)
        self.assertRaises(xml.dom.HierarchyRequestErr, dom.insertBefore, text,
                          elem)
        self.assertRaises(xml.dom.HierarchyRequestErr, dom.replaceChild, text,
                          elem)

        nodemap = elem.attributes
        self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItem,
                          text)
        self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItemNS,
                          text)

        elem.appendChild(text)
        dom.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_minidom.py

示例5: testNamedNodeMapSetItem

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def testNamedNodeMapSetItem(self):
        dom = Document()
        elem = dom.createElement('element')
        attrs = elem.attributes
        attrs["foo"] = "bar"
        a = attrs.item(0)
        self.confirm(a.ownerDocument is dom,
                "NamedNodeMap.__setitem__() sets ownerDocument")
        self.confirm(a.ownerElement is elem,
                "NamedNodeMap.__setitem__() sets ownerElement")
        self.confirm(a.value == "bar",
                "NamedNodeMap.__setitem__() sets value")
        self.confirm(a.nodeValue == "bar",
                "NamedNodeMap.__setitem__() sets nodeValue")
        elem.unlink()
        dom.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_minidom.py

示例6: testAddAttr

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def testAddAttr(self):
        dom = Document()
        child = dom.appendChild(dom.createElement("abc"))

        child.setAttribute("def", "ghi")
        self.confirm(child.getAttribute("def") == "ghi")
        self.confirm(child.attributes["def"].value == "ghi")

        child.setAttribute("jkl", "mno")
        self.confirm(child.getAttribute("jkl") == "mno")
        self.confirm(child.attributes["jkl"].value == "mno")

        self.confirm(len(child.attributes) == 2)

        child.setAttribute("def", "newval")
        self.confirm(child.getAttribute("def") == "newval")
        self.confirm(child.attributes["def"].value == "newval")

        self.confirm(len(child.attributes) == 2)
        dom.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_minidom.py

示例7: testCloneDocumentDeep

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def testCloneDocumentDeep(self):
        doc = parseString("<?xml version='1.0'?>\n"
                    "<!-- comment -->"
                    "<!DOCTYPE doc [\n"
                    "<!NOTATION notation SYSTEM 'http://xml.python.org/'>\n"
                    "]>\n"
                    "<doc attr='value'/>")
        doc2 = doc.cloneNode(1)
        self.confirm(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)),
                "testCloneDocumentDeep: document objects not distinct")
        self.confirm(len(doc.childNodes) == len(doc2.childNodes),
                "testCloneDocumentDeep: wrong number of Document children")
        self.confirm(doc2.documentElement.nodeType == Node.ELEMENT_NODE,
                "testCloneDocumentDeep: documentElement not an ELEMENT_NODE")
        self.confirm(doc2.documentElement.ownerDocument.isSameNode(doc2),
            "testCloneDocumentDeep: documentElement owner is not new document")
        self.confirm(not doc.documentElement.isSameNode(doc2.documentElement),
                "testCloneDocumentDeep: documentElement should not be shared")
        if doc.doctype is not None:
            # check the doctype iff the original DOM maintained it
            self.confirm(doc2.doctype.nodeType == Node.DOCUMENT_TYPE_NODE,
                    "testCloneDocumentDeep: doctype not a DOCUMENT_TYPE_NODE")
            self.confirm(doc2.doctype.ownerDocument.isSameNode(doc2))
            self.confirm(not doc.doctype.isSameNode(doc2.doctype)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_minidom.py

示例8: testUserData

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def testUserData(self):
        dom = Document()
        n = dom.createElement('e')
        self.confirm(n.getUserData("foo") is None)
        n.setUserData("foo", None, None)
        self.confirm(n.getUserData("foo") is None)
        n.setUserData("foo", 12, 12)
        n.setUserData("bar", 13, 13)
        self.confirm(n.getUserData("foo") == 12)
        self.confirm(n.getUserData("bar") == 13)
        n.setUserData("foo", None, None)
        self.confirm(n.getUserData("foo") is None)
        self.confirm(n.getUserData("bar") == 13)

        handler = self.UserDataHandler()
        n.setUserData("bar", 12, handler)
        c = n.cloneNode(1)
        self.confirm(handler.called
                and n.getUserData("bar") is None
                and c.getUserData("bar") == 13)
        n.unlink()
        c.unlink()
        dom.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_minidom.py

示例9: get_layers

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def get_layers(filepath):
    """
    Return the list of inkscape layers in the file

    :param filepath: Path of the svg file
    :rtype: list
    """
    xmldoc = minidom.parse(filepath)

    assert isinstance(xmldoc, minidom.Document)

    _layers = []
    for node in xmldoc.getElementsByTagName('g'):
        if 'inkscape:groupmode' in node.attributes.keys() and node.attributes['inkscape:groupmode'].value == 'layer':
            _layers.append(node)

    return _layers 
开发者ID:libre-money-projects,项目名称:Geconomicus,代码行数:19,代码来源:svg2svg.py

示例10: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __init__(self):
        self.__xmlDoc = Document() 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:4,代码来源:xmlreportgenerator.py

示例11: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __init__(self):
        self.__ts = datetime.datetime.now()
        self.__xmlDoc = Document() 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:5,代码来源:vulneranetxmlreportgenerator.py

示例12: exportXML

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def exportXML(self, filename, encoding="UTF-8"):
        "Export the urls and the forms found in an XML file."
        xml = minidom.Document()
        items = xml.createElement("items")
        xml.appendChild(items)

        for lien in self.browsed:
            get = xml.createElement("get")
            get.setAttribute("url", lien.url)
            items.appendChild(get)

        for form in self.forms:
            post = xml.createElement("post")
            post.setAttribute("url", form[0])
            post.setAttribute("referer", form[2])

            for k, v in form[1].items():
                var = xml.createElement("var")
                var.setAttribute("name", k)
                var.setAttribute("value", v)
                post.appendChild(var)
            items.appendChild(post)

        fd = open(filename, "w")
        xml.writexml(fd, "    ", "    ", "\n", encoding)
        fd.close() 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:28,代码来源:lswww.py

示例13: __xml__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __xml__(self):
        doc = Document()
        root = doc.createElement('matrix')
        for key,value in self.items():
            element = value.__xml__().documentElement
            element.setAttribute('key',key)
            root.appendChild(element)
        doc.appendChild(root)
        return doc 
开发者ID:pynadath,项目名称:psychsim,代码行数:11,代码来源:matrix.py

示例14: __xml__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __xml__(self):
        doc = Document()
        root = doc.createElement('tree')
        if not self.isLeaf():
            if self.branch:
                root.appendChild(self.branch.__xml__().documentElement)
        if isinstance(self.children,Distribution):
            root.appendChild(self.children.__xml__().documentElement)
        else:
            for key,value in self.children.items():
                if isinstance(value,bool):
                    node = doc.createElement('bool')
                    node.setAttribute('value',str(value))
                elif isinstance(value,str):
                    node = doc.createElement('str')
                    node.appendChild(doc.createTextNode(value))
                elif isinstance(value,int):
                    node = doc.createElement('int')
                    node.appendChild(doc.createTextNode(str(value)))
                elif value is None:
                    node = doc.createElement('none')
                else:
                    node = value.__xml__().documentElement
                node.setAttribute('key',str(key))
                root.appendChild(node)
        doc.appendChild(root)
        return doc 
开发者ID:pynadath,项目名称:psychsim,代码行数:29,代码来源:tree.py

示例15: __xml__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Document [as 别名]
def __xml__(self):
        doc = Document()
        root = doc.createElement('plane')
        for vector,threshold,comparison in self.planes:
            node = vector.__xml__().documentElement
            node.setAttribute('threshold',str(threshold))
            node.setAttribute('comparison',str(comparison))
            root.appendChild(node)
        doc.appendChild(root)
        return doc 
开发者ID:pynadath,项目名称:psychsim,代码行数:12,代码来源:plane.py


注:本文中的xml.dom.minidom.Document方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。