我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用xml.dom.getElementsByTagName()。
def from_xml(cls, src): """Generate instance of subclass from an XML string.""" dom = xml.dom.minidom.parseString(src) # Make sure all of the necessary pieces are there. Fail if any # required tags are missing xc = cls() for tag_name, default_or_type in xc.required_tags(): elem = dom.getElementsByTagName(tag_name) if not elem: raise ValueError("Missing XML tag: " + tag_name) tag_type = (default_or_type if isinstance(default_or_type, type) else type(default_or_type)) xc[tag_name] = tag_type(cls._get_text(elem[0].childNodes)) return xc
def testGetElementsByTagName(self): dom = parse(tstfile) self.confirm(dom.getElementsByTagName("LI") == \ dom.documentElement.getElementsByTagName("LI")) dom.unlink()
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())