I'm working with a kind of advertising newspaper that carries only text and some small images. No special trouble at all.
My task is to do completely automated layout of it all, based on XML files (easy as cake... :D ) and scripting, outputing a PDF file to be sent to press.
Using only scripting, until now I could make master spreads, define styles for paragraphs, tables, cell, etc. Then, I was able to import and place the XML file, creating new pages as they are required. Finally, as the printing house needs the PDF to have pages in a number multiple of 4 (due to imposition needs), I also did a script that calculates the ideal number of pages and cuts or adds pages as necessary (easy as cake with strawberry jam!).
Last, I have to generate a TOC - table of contents. Ok, fine, easy. Then, I have to link the text frame where the TOC is (which is a separated story) to the other story - the one with the XML file. Easy, too. Of course, this linking can change the position of elements in the document, so I would have to update the TOC.
Here the trouble begins: updating the TOC deletes all the document.
My question is: I would like other options to solve this issue. Of course a script would do good, but I would like to know some ways to create a TOC that can be updated without messing the document. I've thought of creating an index instead of the usual TOC, but since I've spent a lot of time thinking of that, I've finally decided to ask for some help of you.