Hi everybody,
I want to change the structure of a xml file.
Maybe someone could help me with this.
I have this infile:
Code:
<?xml version="1.0" encoding="utf-8"?>
<cases>
<file name="Reference 19762">
<case>
<name>CaseX - exp</name>
<number>No. 3 Div. 870</number>
<citation>271 Bypl. 44; 122 So. 2d 119; 2005 Bypl. MOPPE 405</citation>
<date>July 17, 2005</date>
<judges>Peter, Ely, Mark.</judges>
</case>
<case>
<name>Comp and Indfi</name>
<number>No. 3 Div. 887</number>
<citation>271 Bypl. 70; 122 So. 2d 360; 2005 Bypl. MOPPE 421</citation>
<date>July 17, 2005</date>
<judges>Mary, Peter, Ely, Perry, Mark.</judges>
</case>
</file>
</cases>
and the output should be:
Code:
<Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="3" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
<Column ss:Width="81.75"/>
<Column ss:Width="75.75"/>
<Column ss:Width="67.5"/>
<Column ss:Width="238.5"/>
<Column ss:Width="62.25"/>
<Column ss:Width="141.75"/>
<Row>
<Cell><Data ss:Type="String">name</Data></Cell>
<Cell><Data ss:Type="String">name2</Data></Cell>
<Cell><Data ss:Type="String">number</Data></Cell>
<Cell><Data ss:Type="String">citation</Data></Cell>
<Cell><Data ss:Type="String">date</Data></Cell>
<Cell><Data ss:Type="String">judges</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Reference 19762</Data></Cell>
<Cell><Data ss:Type="String">CaseX - exp</Data></Cell>
<Cell><Data ss:Type="String">No. 3 Div. 870</Data></Cell>
<Cell><Data ss:Type="String">271 Bypl. 44; 122 So. 2d 119; 2005 Bypl. MOPPE 405</Data></Cell>
<Cell><Data ss:Type="String">July 17, 2005</Data></Cell>
<Cell><Data ss:Type="String">Peter, Ely, Mark.</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Reference 19762</Data></Cell>
<Cell><Data ss:Type="String">Comp and Indfi</Data></Cell>
<Cell><Data ss:Type="String">No. 3 Div. 887</Data></Cell>
<Cell><Data ss:Type="String">271 Bypl. 70; 122 So. 2d 360; 2005 Bypl. MOPPE 421</Data></Cell>
<Cell><Data ss:Type="String">July 17, 2005</Data></Cell>
<Cell><Data ss:Type="String">Mary, Peter, Ely, Perry, Mark.</Data></Cell>
</Row>
</Table>
As you can see, in infile there are 2 blocks of "cases" (it could be more than 2 "cases" blocks. e.g 5, 7, 8 etc.).
Then, in the output the "Row" blocks should be obtained as follow:
Block 1:
Code:
<Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="3" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
Variables here are in
red:
ExpandedRowCount = Number of "Cases" blocks + 1 = 2 + 1 = 3
ExpandedColumnCount="6" (is always equal to 6)
Block 2 (the first "Row" block for headers):
Code:
<Row>
<Cell><Data ss:Type="String">name</Data></Cell>
<Cell><Data ss:Type="String">name2</Data></Cell>
<Cell><Data ss:Type="String">number</Data></Cell>
<Cell><Data ss:Type="String">citation</Data></Cell>
<Cell><Data ss:Type="String">date</Data></Cell>
<Cell><Data ss:Type="String">judges</Data></Cell>
</Row>
This block is always the same text.
Blocks 3,4,...,N ("Row" blocks that are not for headers):
Code:
<Row>
<Cell><Data ss:Type="String">Reference 19762</Data></Cell>
<Cell><Data ss:Type="String">CaseX - exp</Data></Cell>
<Cell><Data ss:Type="String">No. 3 Div. 870</Data></Cell>
<Cell><Data ss:Type="String">271 Bypl. 44; 122 So. 2d 119; 2005 Bypl. MOPPE 405</Data></Cell>
<Cell><Data ss:Type="String">July 17, 2005</Data></Cell>
<Cell><Data ss:Type="String">Peter, Ely, Mark.</Data></Cell>
</Row>
The first value, in
red, is get from the line "
<file name="Reference 19762">" in
infile that only appears once.
The next rows for this block, values in
green, are taken in the same order that they appear in "Cases" block
I can do some basic sed or awk replacements individually, but I don't know how to get a script to do all
things needed as described above.
I hope someone could help me.
Many thanks in advance for any help.
Regards.