我有以下几行XML:
<?xml version="xxx"?>
<doc:document xmlns:doc="some value 1...">
<rdf:RDF xmlns:rdf="some value 2...">
<rdf:Description rdf:about="some value...">
<dct:format xmlns:dct="http://someurl/">some value 3</dct:format>
<dct:title xmlns:dct="http://someurl/">some text of interest to me</dct:title>
</rdf:Description>
</rdf:RDF>
</doc:document>
如何使用Python/ETree获取“我感兴趣的一些文本”?你知道吗
提前感谢您的帮助!你知道吗
您需要通过指定命名空间来查找
title
元素:您必须在每次搜索时传递
namespaces
映射,因此您也可以预先指定并重用:对于示例文档(恢复了名称空间),它提供了:
也可以在XPath表达式中使用命名空间:
这就是使用前缀和
namespaces
映射在内部所做的。你知道吗相关问题 更多 >
编程相关推荐