本文整理匯總了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