I have an XML document based what Excel produces when saving as "XML Spreadsheet 2003 (*.xml)".
The spreadsheet itself contains a header section with a hierarchy of labels:
| A B C D E F G H I -+----------------------------------------------------- 1| a1 a2 2| a11 a12 a13 a21 a22 3| a111 a112 a121 a122 a131 a132 a221 a222
This hierarchy is present on all sheets in the workbook, and looks more or less the same everywhere.
Excel XML works exactly like ordinary HTML tables. (<row>
s that contain <cell>
s). I have been able to transform everything into such a tree structure:
<node title="a1" col="1">
<node title="a11" col="1">
<node title="a111" col="1"/>
<node title="a112" col="2"/>
</node>
<node title="a12" col="3">
<node title="a121" col="3" />
<node title="a122" col="4" />
</node>
<!-- and so on -->
</node>
But here is the complication:
- there is more than one worksheet, so there is a tree for each of them
- the hierarchy may be slightly different on each sheet, the trees will not be equal (for example, sheet 2 may have "a113", while the others don't)
- tree depth is not explicitly limited
- the labels however are meant to be the same across all sheets, which means they can be used for grouping
I'd like to merge these separate trees into one that looks like this:
<node title="a1">
<col on="sheet1">1</col>
<col on="sheet2">1</col>
<node title="a11">
<col on="sheet1">1</col>
<col on="sheet2">1</col>
<node title="a111">
<col on="sheet1">1</col>
<col on="sheet2">1</col>
</node>
<node title="a112">
<col on="sheet1">2</col>
<col on="sheet2">2</col>
</node>
<node title="a113"><!-- different here -->
<col on="sheet2">3</col>
</node>
</node>
<node title="a12">
<col on="sheet1">3</col>
<col on="sheet2">4</col>
<node title="a121">
<col on="sheet1">3</col>
<col on="sheet2">4</col>
</node>
<node title="a122">
<col on="sheet1">4</col>
<col on="sheet2">5</col>
</node>
</node>
<!-- and so on -->
</node>
Ideally I'd like to be able to do the merge before I even build the three structure from the Excel XML (if you get me started on this, it'd be great). But since I have no idea how I would do this, a merge after the trees have been built (i.e.: the situation described above) will be fine.
Thanks for your time. :)