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


Python ElementTree.XMLTreeBuilder方法代码示例

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


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

示例1: xmltoolkit62

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import XMLTreeBuilder [as 别名]
def xmltoolkit62():
    """

    Don't crash when using custom entities.

    >>> xmltoolkit62()
    u'A new cultivar of Begonia plant named \u2018BCT9801BEG\u2019.'

    """
    ENTITIES = {u'rsquo': u'\u2019', u'lsquo': u'\u2018'}
    parser = ET.XMLTreeBuilder()
    parser.entity.update(ENTITIES)
    parser.feed(XMLTOOLKIT62_DOC)
    t = parser.close()
    return t.find('.//paragraph').text 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:17,代码来源:test_xml_etree.py

示例2: __init__

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import XMLTreeBuilder [as 别名]
def __init__(self):
        self.collection_stack = []
        self.ids              = {}
        self.current_data     = []
        self.current_id       = None
        self.current_idref    = None
        self.current_key      = None
        self.root             = None
        self.start_handler    = {
                'dict':       self.start_dict,
                'array':      self.start_array,
        }
        self.end_handler      = {
                'dict':       self.end_dict,
                'key':        self.end_key,
                'true':       self.end_true,
                'false':      self.end_false,
                'integer':    self.end_integer,
                'string':     self.end_string,
                'data':       self.end_data,
        }
        self.attributes       = {
                'integer':    ('size',),
        }
        self.tags = set(self.start_handler.keys()).union(self.end_handler.keys())

    # XMLTreeBuilder calls. 
开发者ID:bazad,项目名称:ida_kernelcache,代码行数:29,代码来源:kplist.py

示例3: kplist_parse

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import XMLTreeBuilder [as 别名]
def kplist_parse(plist):
    """Parse a kernel-style property list."""
    try:
        builder = _KPlistBuilder()
        parser  = XMLTreeBuilder(target=builder)
        parser.feed(plist)
        return parser.close()
    except:
        return None 
开发者ID:bazad,项目名称:ida_kernelcache,代码行数:11,代码来源:kplist.py

示例4: interface

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import XMLTreeBuilder [as 别名]
def interface():
    r"""
    Test element tree interface.

    >>> element = ET.Element("tag")
    >>> check_element(element)
    >>> tree = ET.ElementTree(element)
    >>> check_element(tree.getroot())

    >>> element = ET.Element("t\xe4g", key="value")
    >>> tree = ET.ElementTree(element)
    >>> repr(element)   # doctest: +ELLIPSIS
    "<Element 't\\xe4g' at 0x...>"
    >>> element = ET.Element("tag", key="value")

    Make sure all standard element methods exist.

    >>> check_method(element.append)
    >>> check_method(element.extend)
    >>> check_method(element.insert)
    >>> check_method(element.remove)
    >>> check_method(element.getchildren)
    >>> check_method(element.find)
    >>> check_method(element.iterfind)
    >>> check_method(element.findall)
    >>> check_method(element.findtext)
    >>> check_method(element.clear)
    >>> check_method(element.get)
    >>> check_method(element.set)
    >>> check_method(element.keys)
    >>> check_method(element.items)
    >>> check_method(element.iter)
    >>> check_method(element.itertext)
    >>> check_method(element.getiterator)

    These methods return an iterable. See bug 6472.

    >>> check_method(element.iter("tag").next)
    >>> check_method(element.iterfind("tag").next)
    >>> check_method(element.iterfind("*").next)
    >>> check_method(tree.iter("tag").next)
    >>> check_method(tree.iterfind("tag").next)
    >>> check_method(tree.iterfind("*").next)

    These aliases are provided:

    >>> assert ET.XML == ET.fromstring
    >>> assert ET.PI == ET.ProcessingInstruction
    >>> assert ET.XMLParser == ET.XMLTreeBuilder
    """ 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:52,代码来源:test_xml_etree.py

示例5: parsefile

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import XMLTreeBuilder [as 别名]
def parsefile():
    """
    Test parsing from file.

    >>> tree = ET.parse(SIMPLE_XMLFILE)
    >>> normalize_crlf(tree)
    >>> tree.write(sys.stdout)
    <root>
       <element key="value">text</element>
       <element>text</element>tail
       <empty-element />
    </root>
    >>> tree = ET.parse(SIMPLE_NS_XMLFILE)
    >>> normalize_crlf(tree)
    >>> tree.write(sys.stdout)
    <ns0:root xmlns:ns0="namespace">
       <ns0:element key="value">text</ns0:element>
       <ns0:element>text</ns0:element>tail
       <ns0:empty-element />
    </ns0:root>

    >>> with open(SIMPLE_XMLFILE) as f:
    ...     data = f.read()

    >>> parser = ET.XMLParser()
    >>> parser.version  # doctest: +ELLIPSIS
    'Expat ...'
    >>> parser.feed(data)
    >>> print serialize(parser.close())
    <root>
       <element key="value">text</element>
       <element>text</element>tail
       <empty-element />
    </root>

    >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility
    >>> parser.feed(data)
    >>> print serialize(parser.close())
    <root>
       <element key="value">text</element>
       <element>text</element>tail
       <empty-element />
    </root>

    >>> target = ET.TreeBuilder()
    >>> parser = ET.XMLParser(target=target)
    >>> parser.feed(data)
    >>> print serialize(parser.close())
    <root>
       <element key="value">text</element>
       <element>text</element>tail
       <empty-element />
    </root>
    """ 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:56,代码来源:test_xml_etree.py


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