Extract value from element when second namespace is used in lxml

一曲冷凌霜 提交于 2019-12-06 13:30:47

The Id element in MainClosedCaption belongs to the 2004 namespace. Only an attribute xmlns="..." can change the default namespace; attributes of the form xmlns:something="..." only add a namespace which has to be explicitly declared.

Try this:

from lxml import etree
cpl_parse = etree.parse('filename.xml')
xmluuid = cpl_parse.xpath('//proto2007:MainClosedCaption/proto2004:Id', namespaces={
    'proto2004': 'http://www.digicine.com/PROTO-ASDCP-CPL-20040511#',
    'proto2007': 'http://www.digicine.com/PROTO-ASDCP-CC-CPL-20070926#',
})
for i in xmluuid:
    print(i.text)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!