Python xml.dom 模块,getElementsByTagName() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用xml.dom.getElementsByTagName()

项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
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
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
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
项目:CommunityCellularManager    作者:facebookincubator    | 项目源码 | 文件源码
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
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink()
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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())
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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())
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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())
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink()
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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())
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def testGetElementsByTagName(self):
        dom = parse(tstfile)
        self.confirm(dom.getElementsByTagName("LI") == \
                dom.documentElement.getElementsByTagName("LI"))
        dom.unlink()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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())