使用 Notepad++ 将特定值从 xml 格式提取为逗号分隔值格式 (csv)

使用 Notepad++ 将特定值从 xml 格式提取为逗号分隔值格式 (csv)

我需要使用 Notepad++ 将特定值从 XML 格式提取为逗号分隔值格式 (CSV)

XML 源文件如下所示:源文件

  GRID id="301019" x="**328.217224**" y="**543.844177**" z="**0.000000**" rx="**0.000000** **-1.000000 0.000000**" ry="**1.000000 0.000000 0.000000**" rz="**0.000000 0.000000 1.000000**"/

  GRID id="303001" x="328.217224" y="518.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/

  GRID id="303002" x="328.217224" y="493.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/

  GRID id="303003" x="328.217224" y="468.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/

  GRID id="301020" x="328.217224" y="443.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/

每个网格需要提取 12 个坐标,形式如下:X、Y、Z、xx、xy、xz、zx、yy、yz、zx、zy、zz

因此上述示例的结果应为:

328.217224,543.844177,0.000000,0.000000,-1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000
328.217224,518.844177,0.000000,0.000000,-1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000
328.217224,493.844177,0.000000,0.000000,-1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000
328.217224,468.844177,0.000000,0.000000,-1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000
328.217224,443.844177,0.000000,0.000000,-1.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000

答案1

您可以使用出色的 flatten xml2 Linux 实用程序 (https://manpages.debian.org/stretch/xml2/2csv.1)并从 xml 源开始运行

xml2 <  input.xml | 2csv GRID @id @x @y @z @rx @ry @rz

获得

+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+
| 301019 | 328.217224 | 543.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303001 | 328.217224 | 518.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303002 | 328.217224 | 493.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303003 | 328.217224 | 468.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 301020 | 328.217224 | 443.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+

然后你可以用很多方法用空格分割最后 3 列

在记事本中没有简单的方法可以做到这一点,因为 XML 是一个复杂的文件。您也可以在 Windows 中运行 Linux 实用程序

相关内容