如何解决xmltodict 返回字符串而不是 OrderedDict
鉴于此代码:
import xmltodict
xml = xmltodict.parse('''<?xml version="1.0" encoding="UTF-8"?>
<A>
<B id="one">
<C id="X">1</C>
<C id="Y">2</C>
</B>
<B id="two">
<C id="Z">3</C>
</B>
</A>
''')
for b in xml['A']['B']:
print(b.get('@id'))
for c in b['C']:
print(c)
输出为:
one
<class 'collections.OrderedDict'> OrderedDict([('@id','X'),('#text','1')])
<class 'collections.OrderedDict'> OrderedDict([('@id','Y'),'2')])
two
<class 'str'> @id
<class 'str'> #text
我错过了什么/误解了什么,为什么第二部分表示为字符串?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。