如何将此XML数据解析到Python的表中
我有以下XML,我想将其解析到表中。我一直在环顾四周,找不到一个好的答案。困难的部分是:
- 不同子树中的标题和数据
- 所有内部标签具有相同的名称(TH或TD)
疫苗 | 日期 | 状态 | 剂量 | 路线 | 站点点 | 评论 | ID ID |
---|---|---|---|---|---|---|---|
疫苗A | 星期一,2019年3月15日, | DOME | IMM。 | ||||
疫苗B | TUE,2019年9月20日 | 完成了 | IMM。 |
<ns0:text xmlns:ns0="urn:hl7-org:v3">
<ns0:table border="1" width="100%">
<ns0:thead>
<ns0:tr>
<ns0:th>Vaccine</ns0:th>
<ns0:th>Date</ns0:th>
<ns0:th>Status</ns0:th>
<ns0:th>Dose</ns0:th>
<ns0:th>Route</ns0:th>
<ns0:th>Site</ns0:th>
<ns0:th>Comment</ns0:th>
</ns0:tr>
</ns0:thead>
<ns0:tbody>
<ns0:tr>
<ns0:td>
<ns0:content ID="immunizationDescription1">Vaccin A</ns0:content>
</ns0:td>
<ns0:td>Monday, March 15, 2019 at 4:46:00 pm</ns0:td>
<ns0:td>Done</ns0:td>
<ns0:td>
</ns0:td>
<ns0:td />
<ns0:td />
<ns0:td />
</ns0:tr>
<ns0:tr>
<ns0:td>
<ns0:content ID="immunizationDescription2">Vaccine B</ns0:content>
</ns0:td>
<ns0:td>Tuesday, September 20, 2019 at 12:00:00 am</ns0:td>
<ns0:td>Done</ns0:td>
<ns0:td>
</ns0:td>
<ns0:td />
<ns0:td />
<ns0:td />
</ns0:tr>
</ns0:tbody>
</ns0:table>
</ns0:text>
I have the following xml and I want to parse it into a table. I have been looking around and did not find a good answer. The difficult parts are:
- The header and data in different subtree
- All inner tags have same name (th or td)
Vaccine | Date | Status | Dose | Route | Site | Comment | ID |
---|---|---|---|---|---|---|---|
Vaccine A | Mon,Mar 15,2019 | Done | imm. | ||||
Vaccine B | Tue,Sep 20, 2019 | Done | imm. |
<ns0:text xmlns:ns0="urn:hl7-org:v3">
<ns0:table border="1" width="100%">
<ns0:thead>
<ns0:tr>
<ns0:th>Vaccine</ns0:th>
<ns0:th>Date</ns0:th>
<ns0:th>Status</ns0:th>
<ns0:th>Dose</ns0:th>
<ns0:th>Route</ns0:th>
<ns0:th>Site</ns0:th>
<ns0:th>Comment</ns0:th>
</ns0:tr>
</ns0:thead>
<ns0:tbody>
<ns0:tr>
<ns0:td>
<ns0:content ID="immunizationDescription1">Vaccin A</ns0:content>
</ns0:td>
<ns0:td>Monday, March 15, 2019 at 4:46:00 pm</ns0:td>
<ns0:td>Done</ns0:td>
<ns0:td>
</ns0:td>
<ns0:td />
<ns0:td />
<ns0:td />
</ns0:tr>
<ns0:tr>
<ns0:td>
<ns0:content ID="immunizationDescription2">Vaccine B</ns0:content>
</ns0:td>
<ns0:td>Tuesday, September 20, 2019 at 12:00:00 am</ns0:td>
<ns0:td>Done</ns0:td>
<ns0:td>
</ns0:td>
<ns0:td />
<ns0:td />
<ns0:td />
</ns0:tr>
</ns0:tbody>
</ns0:table>
</ns0:text>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您照顾自己的命名空间,您就应该对这样的东西可以很好,尽管它有点令人费解:
输出(赦免格式):
As long as you take care of your namespace, you should be OK with something like this, though it's a bit convoluted:
Output (pardon the formatting):