本文整理汇总了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
示例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()
示例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())