将xml属性解析为字符串

时间:2016-02-22 23:31:59

标签: python xml parsing

如果我有一个声明为:

的xml属性
for child in  root:
  print(child.attrib)

并打印出我的所有子节点:

{'action': 'Stay', 'response': ''}
{'action': 'Enemy Charging User', 'response': ''}
{'action': 'Move', 'response': ''}

有没有办法可以将动作转换为字符串列表,我可以使用它中的元素?例如'Stay','Enemy Charging User'和'Move'将转换为字符串并存储到名为l1 []的字符串列表中,我可以说调用l1 [0]并打印出'Stay'?

1 个答案:

答案 0 :(得分:1)

l1 = [ child.attrib['action'] for child in root ]
相关问题