當前位置: 首頁>>代碼示例>>Python>>正文


Python dom.documentElement方法代碼示例

本文整理匯總了Python中xml.dom.documentElement方法的典型用法代碼示例。如果您正苦於以下問題:Python dom.documentElement方法的具體用法?Python dom.documentElement怎麽用?Python dom.documentElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xml.dom的用法示例。


在下文中一共展示了dom.documentElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testInsertBeforeFragment

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testInsertBeforeFragment(self):
        dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
        dom.documentElement.insertBefore(frag, None)
        self.confirm(tuple(dom.documentElement.childNodes) ==
                     (orig, c1, c2, c3),
                     "insertBefore(<fragment>, None)")
        frag.unlink()
        dom.unlink()

        dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
        dom.documentElement.insertBefore(frag, orig)
        self.confirm(tuple(dom.documentElement.childNodes) ==
                     (c1, c2, c3, orig),
                     "insertBefore(<fragment>, orig)")
        frag.unlink()
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_minidom.py

示例2: testCloneDocumentDeep

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [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

示例3: testNormalize

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalize(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode("first"))
        root.appendChild(doc.createTextNode("second"))
        self.confirm(len(root.childNodes) == 2
                and root.childNodes.length == 2,
                "testNormalize -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 1
                and root.childNodes.length == 1
                and root.firstChild is root.lastChild
                and root.firstChild.data == "firstsecond"
                , "testNormalize -- result")
        doc.unlink()

        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode(""))
        doc.normalize()
        self.confirm(len(root.childNodes) == 0
                and root.childNodes.length == 0,
                "testNormalize -- single empty node removed")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_minidom.py

示例4: testNormalizeCombineAndNextSibling

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalizeCombineAndNextSibling(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode("first"))
        root.appendChild(doc.createTextNode("second"))
        root.appendChild(doc.createElement("i"))
        self.confirm(len(root.childNodes) == 3
                and root.childNodes.length == 3,
                "testNormalizeCombineAndNextSibling -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 2
                and root.childNodes.length == 2
                and root.firstChild.data == "firstsecond"
                and root.firstChild is not root.lastChild
                and root.firstChild.nextSibling is root.lastChild
                and root.firstChild.previousSibling is None
                and root.lastChild.previousSibling is root.firstChild
                and root.lastChild.nextSibling is None
                , "testNormalizeCombinedAndNextSibling -- result")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_minidom.py

示例5: testNormalizeDeleteWithPrevSibling

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalizeDeleteWithPrevSibling(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode("first"))
        root.appendChild(doc.createTextNode(""))
        self.confirm(len(root.childNodes) == 2
                and root.childNodes.length == 2,
                "testNormalizeDeleteWithPrevSibling -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 1
                and root.childNodes.length == 1
                and root.firstChild.data == "first"
                and root.firstChild is root.lastChild
                and root.firstChild.nextSibling is None
                and root.firstChild.previousSibling is None
                , "testNormalizeDeleteWithPrevSibling -- result")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_minidom.py

示例6: testNormalizeDeleteWithNextSibling

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalizeDeleteWithNextSibling(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode(""))
        root.appendChild(doc.createTextNode("second"))
        self.confirm(len(root.childNodes) == 2
                and root.childNodes.length == 2,
                "testNormalizeDeleteWithNextSibling -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 1
                and root.childNodes.length == 1
                and root.firstChild.data == "second"
                and root.firstChild is root.lastChild
                and root.firstChild.nextSibling is None
                and root.firstChild.previousSibling is None
                , "testNormalizeDeleteWithNextSibling -- result")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_minidom.py

示例7: testNormalizeDeleteWithTwoNonTextSiblings

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalizeDeleteWithTwoNonTextSiblings(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createElement("i"))
        root.appendChild(doc.createTextNode(""))
        root.appendChild(doc.createElement("i"))
        self.confirm(len(root.childNodes) == 3
                and root.childNodes.length == 3,
                "testNormalizeDeleteWithTwoSiblings -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 2
                and root.childNodes.length == 2
                and root.firstChild is not root.lastChild
                and root.firstChild.nextSibling is root.lastChild
                and root.firstChild.previousSibling is None
                and root.lastChild.previousSibling is root.firstChild
                and root.lastChild.nextSibling is None
                , "testNormalizeDeleteWithTwoSiblings -- result")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_minidom.py

示例8: testNormalizeDeleteAndCombine

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testNormalizeDeleteAndCombine(self):
        doc = parseString("<doc/>")
        root = doc.documentElement
        root.appendChild(doc.createTextNode(""))
        root.appendChild(doc.createTextNode("second"))
        root.appendChild(doc.createTextNode(""))
        root.appendChild(doc.createTextNode("fourth"))
        root.appendChild(doc.createTextNode(""))
        self.confirm(len(root.childNodes) == 5
                and root.childNodes.length == 5,
                "testNormalizeDeleteAndCombine -- preparation")
        doc.normalize()
        self.confirm(len(root.childNodes) == 1
                and root.childNodes.length == 1
                and root.firstChild is root.lastChild
                and root.firstChild.data == "secondfourth"
                and root.firstChild.previousSibling is None
                and root.firstChild.nextSibling is None
                , "testNormalizeDeleteAndCombine -- result")
        doc.unlink() 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:22,代碼來源:test_minidom.py

示例9: testGetElementsByTagName

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_minidom.py

示例10: _create_fragment_test_nodes

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def _create_fragment_test_nodes(self):
        dom = parseString("<doc/>")
        orig = dom.createTextNode("original")
        c1 = dom.createTextNode("foo")
        c2 = dom.createTextNode("bar")
        c3 = dom.createTextNode("bat")
        dom.documentElement.appendChild(orig)
        frag = dom.createDocumentFragment()
        frag.appendChild(c1)
        frag.appendChild(c2)
        frag.appendChild(c3)
        return dom, orig, c1, c2, c3, frag 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_minidom.py

示例11: testAppendChild

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testAppendChild(self):
        dom = parse(tstfile)
        dom.documentElement.appendChild(dom.createComment(u"Hello"))
        self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
        self.confirm(dom.documentElement.childNodes[-1].data == "Hello")
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_minidom.py

示例12: testReplaceChildFragment

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testReplaceChildFragment(self):
        dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
        dom.documentElement.replaceChild(frag, orig)
        orig.unlink()
        self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
                "replaceChild(<fragment>)")
        frag.unlink()
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_minidom.py

示例13: testElement

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testElement(self):
        dom = Document()
        dom.appendChild(dom.createElement("abc"))
        self.confirm(dom.documentElement)
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_minidom.py

示例14: testAAA

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testAAA(self):
        dom = parseString("<abc/>")
        el = dom.documentElement
        el.setAttribute("spam", "jam2")
        self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
        a = el.getAttributeNode("spam")
        self.confirm(a.ownerDocument is dom,
                "setAttribute() sets ownerDocument")
        self.confirm(a.ownerElement is dom.documentElement,
                "setAttribute() sets ownerElement")
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_minidom.py

示例15: testAAB

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import documentElement [as 別名]
def testAAB(self):
        dom = parseString("<abc/>")
        el = dom.documentElement
        el.setAttribute("spam", "jam")
        el.setAttribute("spam", "jam2")
        self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
        dom.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_minidom.py


注:本文中的xml.dom.documentElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。