當前位置: 首頁>>代碼示例>>Python>>正文


Python etree.cElementTree方法代碼示例

本文整理匯總了Python中xml.etree.cElementTree方法的典型用法代碼示例。如果您正苦於以下問題:Python etree.cElementTree方法的具體用法?Python etree.cElementTree怎麽用?Python etree.cElementTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xml.etree的用法示例。


在下文中一共展示了etree.cElementTree方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_attribute_on_first_child

# 需要導入模塊: from xml import etree [as 別名]
# 或者: from xml.etree import cElementTree [as 別名]
def set_attribute_on_first_child(docfrag, name, value, treeName):
    """naively sets an attribute on the first child of the document
    fragment passed in"""
    setter = {'ElementTree': lambda d: d[0].set,
              'DOM': lambda d: d.firstChild.setAttribute}
    setter['cElementTree'] = setter['ElementTree']
    try:
        setter.get(treeName, setter['DOM'])(docfrag)(name, value)
    except AttributeError:
        setter['ElementTree'](docfrag)(name, value) 
開發者ID:xtiankisutsa,項目名稱:MARA_Framework,代碼行數:12,代碼來源:test_treewalkers.py

示例2: get_etree

# 需要導入模塊: from xml import etree [as 別名]
# 或者: from xml.etree import cElementTree [as 別名]
def get_etree():
    global _etree
    if _etree is not None:
        return _etree
    try:
        from lxml import etree as _etree
    except ImportError:
        try:
            from xml.etree import cElementTree as _etree
        except ImportError:
            try:
                from xml.etree import ElementTree as _etree
            except ImportError:
                raise TypeError('lxml or etree not found')
    return _etree 
開發者ID:gita,項目名稱:BhagavadGita,代碼行數:17,代碼來源:client.py


注:本文中的xml.etree.cElementTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。