當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。