Mapping a Flat Structure to a Hierarchy

I have written at least one preprocessing program for the very real problem of mapping a flat structure to a hierarchy. Some low-end bookkeeping systems export invoices one line item at a time, with each line item containing all the information about the invoice. Each line in the file has the same format. This is the basic organization of the files handled by our CSVToXML converter in Chapter 7. So, how do we turn something like this into a more conventional invoice with a header section and a detail section for each line item? It's really not very difficult.

Here's our source file. It's an example invoice from Chapter 7 with two line items.

Source (FlatToHierarchy.xml)
 <?xml version="1.0" encoding="UTF-8"?> ...

Get Using XML with Legacy Business Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.