【发布时间】:2019-02-21 12:34:19
【问题描述】:
我需要生成下面的文件。使用python解析XML样本:
示例 XML
<fruits>
<tag beginTime="20181125020000" endTime="20181202020000">
<EventId>16778</EventId>
<item color="red">
<name>apple</name>
<count>1</count>
<subtag>
<Info name="Eid">396</Info>
<Info name="New">397</Info>
</subtag>
</item>
<item color="yellow">
<name>banana</name>
<count>2</count>
<subtag>
<Info name="Eid">500</Info>
<Info name="New">650</Info>
<Info name="Col">999</Info>
</subtag>
</item>
</tag>
期望的输出:
20181125020000|20181202020000|16778|red|apple|1|Eid;396;New;397|
20181125020000|20181202020000|16778|yelow|banana|1|Eid;500;New;650;Col;999|
【问题讨论】:
-
嗨@David,你能告诉我们你到目前为止的尝试吗?
-
您将需要一个支持使用 xpath 的解析器。像这样的东西:docs.python.org/2/library/xml.etree.elementtree.html 和 xmlsoft.org/python.html。解析 html 的工具也可以工作,因为 html 接近 xml
标签: python xml parsing elementtree minidom