【问题标题】:Printing Attribute Values in python-amara在 python-amara 中打印属性值
【发布时间】:2010-09-16 14:25:59
【问题描述】:

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

有什么想法吗?

【问题讨论】:

    标签: python xml-parsing amara


    【解决方案1】:

    要以您尝试的方式访问元素,您必须使用

    from amara import bindery
    doc = bindery.parse('h.xml')
    

    而不是

    doc = amara.parse('h.xml')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      相关资源
      最近更新 更多