【发布时间】:2012-12-31 08:36:18
【问题描述】:
我正在尝试将 xml 文件转换为 csv 文件。我有一个这样的输入 xml 文件:
<Row>
<Cell>
<Data Type="String" >START</Data>
</Cell>
<Cell>
<Data Type="DateTime" >2013-01-15T21:30:42</Data>
</Cell>
<Cell>
<Data Type="String" ></Data>
</Cell>
<Cell>
<Data Type="String" >Start 'suite8'</Data>
</Cell>
<Cell>
<Data Type="String" >Test 'suite8' started</Data>
</Cell>
<Cell>
<Data Type="String" ></Data>
</Cell>
</Row>
<Row/>
<Row>
<Cell>
<Data Type="String" >START_TEST_CASE</Data>
</Cell>
<Cell>
<Data Type="DateTime" >2013-01-15T21:30:42</Data>
</Cell>
<Cell>
<Data Type="String" ></Data>
</Cell>
<Cell>
<Data Type="String" >Start 'case1'</Data>
</Cell>
<Cell>
<Data Type="String" >Test Case 'case1' started</Data>
</Cell>
<Cell>
<Data Type="String" >case1</Data>
</Cell>
</Row>
我对标签<Data Type="String" > 和</Data> 之间的位感兴趣。此外,当标签<Row> 出现时应该开始一个新行。
我想要的输出 csv 文件应该是这样的:
START,2013-01-15T21:30:42,,Test 'suite8' started
START_TEST_CASE,2013-01-15T21:30:42,,Start 'case1',Test Case 'case1' started,case1
我希望这足够清楚,非常感谢任何帮助:) 谢谢!
【问题讨论】:
-
你最好的选择是一个 perl 或 python 脚本,它只有几行,但比任何 shell/grep/sed/awk 都更健壮和更快地编写。工作。你愿意接受这样的选择吗?
-
您确实意识到您想要的输出实际上不是格式正确的 CSV?您的行之间的“列”数不同......
-
你应该使用 XML 解析器。
-
sds:我对其他选项持开放态度,但我对 perl 或 python 脚本的了解更少。我是新手:(
-
tink:我现在意识到了,谢谢:)