本文整理汇总了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]
示例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
示例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
示例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