python - 在 python-amara 中打印属性值

标签 python xml-parsing amara

我正在尝试使用 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/

相关文章:

python - 计算 Pandas 数据框中两行 LDA 分布之间的距离

python - lambda可以有多个返回

python - 跳转到 emacs 中的模型/ View / Controller

xml - 如何在忽略嵌套元素的情况下在 GO 中解析巨大的 xml?

go - Go 中的解码返回空白输出

c# - xml 解析字符引用 : invalid xmlChar value 0

python - 在 Python 中从 amara 切换到 lxml

python-pptx:有什么办法使文本垂直?