0

I need to extract specific values from XML format to a comma-separated value format (CSV) with Notepad++

The XML source file looks like:source file

  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 coordinates per grid need to be extracted in the following form: X,Y,Z,xx,xy,xz,zx,yy,yz,zx,zy,zz

So the sample above should result in:

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 Answer 1

0

You can use the great flatten xml2 Linux utility (https://manpages.debian.org/stretch/xml2/2csv.1) and starting from your xml source, run

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

to obtain

+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+
| 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 |
+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+

Then you can split the last 3 columns by space in a lot of way

In notepad there is not a simple way to do it, because XML is a complex file. You can run Linux utility also in Windows

3
  • 1
    Thanks for your response. This might be the solution I am looking for, but I do not know how to run this utility in Windows. Apr 19, 2020 at 12:53
  • @IvanKrajnc you could enable WSL and install Ubuntu. You will have a Linux shell inside windows, in which you can install xml2 dataquest.io/blog/tutorial-install-linux-on-windows-wsl
    – aborruso
    Apr 19, 2020 at 13:49
  • Thanks again for being helpful. Apr 19, 2020 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .