[英]How to parse an XML file with multiple non-specific elements
I'm trying to parse a list of cases that is returned from the Fogbugz API. 我正在尝试分析从Fogbugz API返回的案例列表。
Current code: 当前代码:
from fogbugz import FogBugz
from datetime import datetime, timedelta
import fbSettings
fb = FogBugz(fbSettings.URL, fbSettings.TOKEN)
resp = fb.search(q='project:"Python Testing"',cols='ixBug')
print resp.cases.case.ixbug.string
The problem is that the XML has multiple cases returned simply as case. 问题是XML有多个返回的大小写只是作为大小写而已。 For instance my test search back the following: 例如,我的测试搜索返回以下内容:
<response>
<cases count="3">
<case ixbug="133529" operations="edit,assign,resolve,email,remind">
<ixbug>
133529
</ixbug>
</case>
<case ixbug="133528" operations="edit,assign,resolve,email,remind">
<ixbug>
133528
</ixbug>
</case>
<case ixbug="133527" operations="edit,assign,resolve,email,remind">
<ixbug>
133527
</ixbug>
</case>
</cases>
</response>
But 但
print resp.cases.case.ixbug.string
only returns the first case number in the XML, ignoring the other two. 仅返回XML中的第一个案例编号,而忽略其他两个。 How can I modify my print statement to return all three case numbers? 如何修改打印语句以返回所有三个案例编号?
from fogbugz import FogBugz
import fbSettings
fb = FogBugz(fbSettings.URL, fbSettings.TOKEN)
resp = fb.search(q='project:"Python Testing"',cols='ixBug')
# printing
for case in resp.cases.findAll('case'):
print case.ixbug.string
# store in a list
l = [case.ixbug.string for case in resp.cases.findAll('case')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.