我正在为以下情况而苦苦挣扎。我有一个以下格式的 XML 文件:
<event>
<attribute type="NAME">John</attribute>
<attribute type="TASK">Buy</attribute>
<attribute type="DATE">12052017</attribute>
</event>
<event>
<attribute type="NAME">John</attribute>
<attribute type="RESOURCE">Dollar</attribute>
<attribute type="DATE">13052017</attribute>
</event>
我需要将其转换为 CSV 文件。结果应该是:
John,Buy,,12052017
John,,Dollar,13052017
我正在使用我为 Notepad++ 编写的一个小型 Python 脚本,它搜索并删除不应该在字符串中的所有内容。例如:
editor.rereplace('\r\n <attribute type="NAME">', '');
这工作正常,但它弄乱了属性的顺序(因为如果它没有找到<attribute type="TASK">
它不会放置额外的,
. 结果是:
John,Buy,12052017
John,Dollar,13052017
属性 TASK 和 RESOURCE 之间没有区别。
我检查了不同的主题,但没有一个真正涵盖我的问题。可以帮我一个便宜的把戏或给我一个工具。