我正在尝试使用 python-amara 解析 xml 文件。
doc = amara.parse('h.xml')
assert doc.xml_type == tree.entity.xml_type
m = doc.xml_children[0]
print m
当我这样做时,它给出了
amara.tree.element at 0x94c864c: name u'HOP', 0 namespaces, 0 attributes, 93 children
但是当我尝试这个时:
print doc.HOP.A.D
它说:
AttributeError: 'amara.tree.entity' object has no attribute 'HOP'
有什么想法吗?
最佳答案
要以您想要的方式访问元素,您必须使用
from amara import bindery
doc = bindery.parse('h.xml')
代替
doc = amara.parse('h.xml')
关于python - 在 python-amara 中打印属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3727633/