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


Python dom.unlink方法代碼示例

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


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

示例1: testInsertBeforeFragment

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

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

示例3: testNamedNodeMapSetItem

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

示例4: testAddAttr

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

示例5: testNormalize

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

示例6: testNormalizeCombineAndNextSibling

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

示例7: testNormalizeDeleteWithPrevSibling

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

示例8: testNormalizeDeleteWithNextSibling

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

示例9: testNormalizeDeleteWithTwoNonTextSiblings

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

示例10: testUserData

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

示例11: testParseFromFile

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import unlink [as 別名]
def testParseFromFile(self):
        dom = parse(StringIO(open(tstfile).read()))
        dom.unlink()
        self.confirm(isinstance(dom,Document)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_minidom.py

示例12: testGetElementsByTagName

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

示例13: testAppendChild

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

示例14: testReplaceChildFragment

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

示例15: testNonZero

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


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