python如何解析xml格式的字符串,最好解析成键值对的那种,
<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?><Response><statusCode>000000</sta...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<statusCode>000000</statusCode>
<SubAccount>
<dateCreated>2014-06-18 10:15:53.0</dateCreated><subAccountSid>79b9dc20f68e11e3b12dd89d672b35d8</subAccountSid><voipAccount>81620600000002</voipAccount>
</SubAccount>
<SubAccount>
<dateCreated>2014-06-18 15:20:39.0</dateCreated><subAccountSid>0ca54380f6b911e3b12dd89d672b35d8</subAccountSid><voipAccount>81620600000003</voipAccount>
</SubAccount>
<totalCount>2</totalCount>
</Response>
例如这样的xml 展开
<Response>
<statusCode>000000</statusCode>
<SubAccount>
<dateCreated>2014-06-18 10:15:53.0</dateCreated><subAccountSid>79b9dc20f68e11e3b12dd89d672b35d8</subAccountSid><voipAccount>81620600000002</voipAccount>
</SubAccount>
<SubAccount>
<dateCreated>2014-06-18 15:20:39.0</dateCreated><subAccountSid>0ca54380f6b911e3b12dd89d672b35d8</subAccountSid><voipAccount>81620600000003</voipAccount>
</SubAccount>
<totalCount>2</totalCount>
</Response>
例如这样的xml 展开
3个回答
2014-07-01
展开全部
有现成的库可以用,xml.etree.ElementTree,或者xml.dom.minidom,ET相对来说简单一些,而minidom配上node缓存也是一种不错的实现,原理都一样,就是把xml先转化为dom树。这两个库可以参考官方文档,xml以及dom树可以参考w3school
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询