当前位置: 首页>>代码示例>>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;未经允许,请勿转载。