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


Python dom.createComment方法代碼示例

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


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

示例1: testAppendChild

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

示例2: testNonZero

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

示例3: testRenameOther

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import createComment [as 別名]
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_minidom.py

示例4: testWholeText

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import createComment [as 別名]
def testWholeText(self):
        doc = parseString("<doc>a</doc>")
        elem = doc.documentElement
        text = elem.childNodes[0]
        self.assertEqual(text.nodeType, Node.TEXT_NODE)

        self.checkWholeText(text, "a")
        elem.appendChild(doc.createTextNode("b"))
        self.checkWholeText(text, "ab")
        elem.insertBefore(doc.createCDATASection("c"), text)
        self.checkWholeText(text, "cab")

        # make sure we don't cross other nodes
        splitter = doc.createComment("comment")
        elem.appendChild(splitter)
        text2 = doc.createTextNode("d")
        elem.appendChild(text2)
        self.checkWholeText(text, "cab")
        self.checkWholeText(text2, "d")

        x = doc.createElement("x")
        elem.replaceChild(x, splitter)
        splitter = x
        self.checkWholeText(text, "cab")
        self.checkWholeText(text2, "d")

        x = doc.createProcessingInstruction("y", "z")
        elem.replaceChild(x, splitter)
        splitter = x
        self.checkWholeText(text, "cab")
        self.checkWholeText(text2, "d")

        elem.removeChild(splitter)
        self.checkWholeText(text, "cabd")
        self.checkWholeText(text2, "cabd") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:37,代碼來源:test_minidom.py

示例5: testSerializeCommentNodeWithDoubleHyphen

# 需要導入模塊: from xml import dom [as 別名]
# 或者: from xml.dom import createComment [as 別名]
def testSerializeCommentNodeWithDoubleHyphen(self):
        doc = create_doc_without_doctype()
        doc.appendChild(doc.createComment("foo--bar"))
        self.assertRaises(ValueError, doc.toxml) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_minidom.py


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