This is what it looks like now
<Titre_2>first level 01</Titre_2>
<Titre_2>second level 01</Titre_2>
<Titre_2>third level 01</Titre_2>
<Titre_3_ch1>deepest01</Titre_3_ch1>
<Titre_3_ch1>deepest02</Titre_3_ch1>
<Titre_3_ch1>deepest03</Titre_3_ch1>
<Titre_2>third level 02</Titre_2>
<Titre_3_ch1>deepest04</Titre_3_ch1>
<Titre_3_ch1>deepest05</Titre_3_ch1>
<Titre_3_ch1>deepest06</Titre_3_ch1>
<Titre_2>second level 02</Titre_2>
<Titre_2>third level 03</Titre_2>
<Titre_3_ch2>deepest07</Titre_3_ch2>
<Titre_3_ch2>deepest08</Titre_3_ch2>
<Titre_3_ch2>deepest09</Titre_3_ch2>
<Titre_3_ch2>deepest10</Titre_3_ch2>
and this is an example of the structure it should get:
<TOC.BLK>
<TOC.ITEM>
<ITEM.CONT>first level 01</ITEM.CONT>
</TOC.ITEM>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>second level 01</TOC.HD.CONT>
</TOC.HD>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>third level 01</TOC.HD.CONT>
</TOC.HD>
<TOC.ITEM>
<ITEM.CONT>deepest 01</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 02</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 03</ITEM.CONT>
</TOC.ITEM>
</TOC.BLK>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>third level 02</TOC.HD.CONT>
</TOC.HD>
<TOC.ITEM>
<ITEM.CONT>deepest 04</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 05</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 06</ITEM.CONT>
</TOC.ITEM>
</TOC.BLK>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>third level 03</TOC.HD.CONT>
</TOC.HD>
<TOC.ITEM>
<ITEM.CONT>deepest 07</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 08</ITEM.CONT>
</TOC.ITEM>
</TOC.BLK>
</TOC.BLK>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>second level 02</TOC.HD.CONT>
</TOC.HD>
<TOC.BLK>
<TOC.HD>
<TOC.HD.CONT>third level 03</TOC.HD.CONT>
</TOC.HD>
<TOC.ITEM>
<ITEM.CONT>deepest 09</ITEM.CONT>
</TOC.ITEM>
<TOC.ITEM>
<ITEM.CONT>deepest 10</ITEM.CONT>
</TOC.ITEM>
</TOC.BLK>
</TOC.BLK>
</TOC.BLK>
Or to put it differently: the number of sequential titles with the same name dictates the levels they are in
So what has to happen:
everything that starts with <Titre_3>
has to get <ITEM.CONT>
around it
every <Titre_2>
(this is obviously the tricky part) has to be evaluated:
traversing the xml from top to bottom there are 3 possible block-levels:
- 3x Titre_2
- first one = highest level => contains all deeper levels (there is only 1 such level - so it wraps all others)
- second one = level 2 => contains all deeper levels (wraps all level 3 blocks that follow it)
- third one = level 3 => contains all deeper levels (
<ITEM>
)(wraps the deepest levels that follow it)
- 2x Titre_2
- first one = level 2 => contains all deeper levels (wraps all level 3 blocks that follow it)
- second one = level 3 => contains all deeper levels (wraps the deepest levels that follow it)
- 1x Titre_2
- level 3 = contains all deeper levels(wraps the deepest levels that follow it)