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


Python dom.getElementsByTagName方法代码示例

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


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

示例1: testNormalizedAfterLoad

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import getElementsByTagName [as 别名]
def testNormalizedAfterLoad(self):
        """
        Introduced this test on jython because 
        1. Cpython guarantees, by the use of xml.dom.expatbuilder, 
           that all text nodes are normalized after loading.
        2. Jython has no expat, and thus uses xml.dom.pulldom.parse 
           (which uses any java SAX2 compliant parser), and which makes 
           no guarantees about text node normalization.
        Thus we have to check if text nodes are normalized after a parse.
        See this bug for further information
        minidom chunks the character input on multi-line values
        http://bugs.jython.org/issue1614
        """
        num_lines = 2
        # Up to 16K lines should be enough to guarantee failure without normalization
        while num_lines <= 2**14:
            doc_content = "\n".join( ("Line %d" % i for i in xrange(num_lines)) )
            doc_text = "<document>%s</document>" % doc_content
            dom = parseString(doc_text)
            node_content = dom.getElementsByTagName("document")[0].childNodes[0].nodeValue
            self.confirm(node_content == doc_content, "testNormalizedAfterLoad")
            num_lines *= 2 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:24,代码来源:test_minidom.py

示例2: testGetElementsByTagName

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import getElementsByTagName [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

示例3: test_toprettyxml_preserves_content_of_text_node

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import getElementsByTagName [as 别名]
def test_toprettyxml_preserves_content_of_text_node(self):
        # see issue #4147
        for str in ('<B>A</B>', '<A><B>C</B></A>'):
            dom = parseString(str)
            dom2 = parseString(dom.toprettyxml())
            self.assertEqual(
                dom.getElementsByTagName('B')[0].childNodes[0].toxml(),
                dom2.getElementsByTagName('B')[0].childNodes[0].toxml()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_minidom.py


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