Python中文
首页
教程
问答
标签
搜索
登录
注册
如何读取下面的XML并获取“host”,“status”,“owner”,“user-template-01”和“test-id”的值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<pre><code>XML = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Entities TotalResults="101" PageSize="100" PageNumber="1"> <Entity Type="run"> <Fields> <Field Name="host"> <Value>osdc-vw64</Value> </Field> <Field Name="status"> <Value>Passed</Value> </Field> <Field Name="owner"> <Value>Aspeg</Value> </Field> <Field Name="user-template-01"> <Value>1941896</Value> </Field> <Field Name="test-id"> <Value>72769</Value> </Field> </Fields> </Entity> <Entity Type="run"> <Fields> <Field Name="host"> <Value>osdc-57</Value> </Field> <Field Name="status"> <Value>Passed</Value> </Field> <Field Name="owner"> <Value>spana</Value> </Field> <Field Name="user-template-01"> <Value>1941896</Value> </Field> <Field Name="test-id"> <Value>72769</Value> </Field> </Fields> </Entity> </Entities>""" </code></pre> <p>我用过:</p> <pre><code>from xml.etree import ElementTree as ET root = ET.fromstring(XML) print root.tag </code></pre> <p>我不知道现在该怎么办。。。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<pre><code>import xml.etree.ElementTree as ET tree = ET.parse('hai.xml') root = tree.getroot() for child in root: print child.tag, child.attrib for a in child: print a.tag for b in a: print b.attrib , b[0].text </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
plt.savefig不会覆盖现有文件
3 回答
plt.savefig不保存图像
8 回答
plt.savefig在jupyter笔记本中不起作用
5 回答
plt.savefig在从另一个fi调用时停止工作
7 回答
plt.savefig在调用plt.show之前保存空数字
3 回答
plt.save不创建png文件
6 回答
plt.scatter overlay分类数据帧列
5 回答
Plt.Scatter:如何添加title、xlabel和ylab
9 回答
plt.scatter()绘图与Matplotlib中的plt.plot()绘图类似
1 回答
plt.scatter错误'NoneType'对象在成功运行后没有属性'sqrt'
8 回答
plt.set_title()中的标题字符串有误
5 回答
plt.show()
9 回答
plt.show()不在Jupyter笔记本上渲染任何内容
6 回答
plt.show()不打印plt.plot only plt.scatter
8 回答
plt.show()不显示三维散射图像
1 回答
plt.show()不显示任何内容
8 回答
plt.show()不显示数据,而是保留它供下一个图表使用(spyder)
8 回答
plt.show()使终端挂起
7 回答
plt.show()无法使用此代码
2 回答
plt.show()没有打开新的图形风
2 回答