本文整理汇总了Python中lxml.etree.XML.findall方法的典型用法代码示例。如果您正苦于以下问题:Python XML.findall方法的具体用法?Python XML.findall怎么用?Python XML.findall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree.XML
的用法示例。
在下文中一共展示了XML.findall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_gir
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import findall [as 别名]
def parse_gir(gir_path):
"""Extract everything from a gir file"""
print("Parsing {}".format(gir_path))
parser = XMLParser(encoding="utf-8", recover=True)
content = open(gir_path).read()
root = XML(content, parser)
namespace = root.findall("{%s}namespace" % XMLNS)[0]
namespace_content = extract_namespace(namespace)
return namespace_content
示例2: process_update
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import findall [as 别名]
def process_update(self, xml):
messages = []
xml = XML(xml)
msgs = xml.findall("log/msg")
for msg in msgs:
author = msg.findtext("author")
text = msg.findtext("text")
messages.append(ChatMessage(author, text))
self.messages = messages
示例3: _add_children
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import findall [as 别名]
def _add_children(self, bus, service):
'''Add the child nodes found by introspection'''
self._children= {};
xml = self._object.Introspect()
data = XML(xml)
# add all child nodes
for child in data.findall('node'):
name = child.get('name')
if name == "/":
continue
child_path = self.object.object_path
# root is reported as /, don't make it //
if child_path != "/":
child_path += "/"
child_path += name
self._children[name] = Dbusitem(bus, service, child_path)
示例4: _mock_manager_3foobar_warnings
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import findall [as 别名]
def _mock_manager_3foobar_warnings(self, *args, **kwargs):
cmd = """
<load-configuration action="set" format="text">
<configuration-set>
delete interfaces ge-0/0/0
delete protocols ospf
delete policy-options prefix-list foo
</configuration-set>
</load-configuration>
"""
rsp_string = """
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R4/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:1f3dfa00-3434-414a-8aa8-0073590c5812">
<load-configuration-results>
<rpc-error>
<error-severity>warning</error-severity>
<error-message>
foo boom
</error-message>
</rpc-error>
<rpc-error>
<error-severity>warning</error-severity>
<error-message>
boom bar
</error-message>
</rpc-error>
<rpc-error>
<error-severity>warning</error-severity>
<error-message>
foo bar
</error-message>
</rpc-error>
<ok/>
</load-configuration-results>
</rpc-reply>
"""
rsp = XML(rsp_string)
errors = []
for err in rsp.findall('.//'+qualify('rpc-error')):
errors.append(RPCError(err))
raise RPCError(rsp, errs=errors)