如何使用split函数或Python中更通用的方法将带有xml标记的字符串转换为字典?
我有一个字符串,它实际上是一个大的xml结构字符串。 我想把这个字符串转换成字典,这样我就可以快速获取键值对。我该怎么做?这里怎么走 我在用蟒蛇3如何使用split函数或Python中更通用的方法将带有xml标记的字符串转换为字典?,python,python-3.x,Python,Python 3.x,我有一个字符串,它实际上是一个大的xml结构字符串。 我想把这个字符串转换成字典,这样我就可以快速获取键值对。我该怎么做?这里怎么走 我在用蟒蛇3 <TDS xmlns="http://uburw"> <odour> <state> <order-number>AE:9E:7A:4E:8A:15</order-number> <oper-order-age>600&l
<TDS xmlns="http://uburw">
<odour>
<state>
<order-number>AE:9E:7A:4E:8A:15</order-number>
<oper-order-age>600</oper-order-age>
<oper-order-time>200</oper-order-time>
<oper-order-delay>1500</oper-order-delay>
<branch-root>80008e5d3c4d1572</branch-root>
<branch-root-path-cost>200000000</branch-root-path-cost>
<branch-root-interface>20</branch-root-interface>
<branch-root-if>
<branch-base-name>ge2</branch-base-name>
<branch-ext-id/>
</branch-root-if>
<time-since-top-change>191816</time-since-top-change>
<function-changes>1</function-changes>
<branch-root-hops>1</branch-root-hops>
</state>
<leaves>
<leaf>
<leaf-name>ge1</leaf-name>
</leaf>
<leaves>
AE:9E:7A:4E:8A:15
600
200
1500
80008e5d3c4d1572
200000000
20
ge2
191816
1.
1.
ge1
做到这一点非常简单
例如:
xmltodict.parse("""
<?xml version="1.0" ?>
<person>
<name>john</name>
<age>20</age>
</person>""")
欢迎来到SO!到目前为止你试过什么?。。。将其视为一个起点。
{u'person': {u'age': u'20', u'name': u'john'}}