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


Python etree.FunctionNamespace方法代碼示例

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


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

示例1: set_xpathfunc

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import FunctionNamespace [as 別名]
def set_xpathfunc(fname, func):
    """Register a custom extension function to use in XPath expressions.

    The function ``func`` registered under ``fname`` identifier will be called
    for every matching node, being passed a ``context`` parameter as well as
    any parameters passed from the corresponding XPath expression.

    If ``func`` is ``None``, the extension function will be removed.

    See more `in lxml documentation`_.

    .. _`in lxml documentation`: http://lxml.de/extensions.html#xpath-extension-functions

    """
    ns_fns = etree.FunctionNamespace(None)
    if func is not None:
        ns_fns[fname] = func
    else:
        del ns_fns[fname] 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:21,代碼來源:xpathfuncs.py

示例2: register_xpath_extensions

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import FunctionNamespace [as 別名]
def register_xpath_extensions():
    ns = etree.FunctionNamespace("http://mailgun.net")
    ns.prefix = 'mg'
    ns['text_content'] = text_content
    ns['tail'] = tail 
開發者ID:mailgun,項目名稱:talon,代碼行數:7,代碼來源:quotations.py

示例3: parse_schema

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import FunctionNamespace [as 別名]
def parse_schema(schema_xml_str):
    xml = etree.XML(schema_xml_str)
    tree = etree.ElementTree(xml)
    root = tree.getroot()
    for ns in root.nsmap:
        xpath_ns = etree.FunctionNamespace(root.nsmap[ns])
        xpath_ns.prefix = ns
    sequences = tree.xpath(
        '//xsd:schema/xsd:complexType/xsd:complexContent/xsd:extension/xsd:sequence/xsd:element')
    schema_source = {}
    for element in sequences:
        schema_source[element.attrib['name']] = element.attrib['type']
    return schema_source 
開發者ID:MapStory,項目名稱:mapstory,代碼行數:15,代碼來源:utils.py

示例4: parse_wfst_response

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import FunctionNamespace [as 別名]
def parse_wfst_response(schema_xml_str):
    xml = etree.XML(schema_xml_str)
    tree = etree.ElementTree(xml)
    root = tree.getroot()
    for ns in root.nsmap:
        xpath_ns = etree.FunctionNamespace(root.nsmap[ns])
        xpath_ns.prefix = ns
    summary_element = tree.xpath(
        '//wfs:TransactionResponse/wfs:TransactionSummary')
    summary = {}
    for child in summary_element[0].getchildren():
        summary[child.tag.split('}')[1]] = child.text
    return summary 
開發者ID:MapStory,項目名稱:mapstory,代碼行數:15,代碼來源:utils.py


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