【发布时间】:2015-01-31 19:07:24
【问题描述】:
test.xml:
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://example.com" xmlns:foo="http://example.com/bar">
<foo:Child>yikes</foo:Child>
</Root>
test.py:
from lxml import objectify
root = objectify.fromstring(file('test.xml').read())
print root.attrib
输出:
{}
如何获取前缀声明? IE。类似:
{
"xmlns": "http://example.com",
"xmlns:foo": "http://example.com/bar"}
更新:
root.keys()、root.items() 和 root.values() 分别产生 []、[] 和 {}。
【问题讨论】:
-
你试过root.keys吗?根.项目()? root.values()?
标签: python xml lxml xml-namespaces objectify