<p>I have an AppleScript program which creates XML tags and elements within an Adobe InDesign document. The data is in tables, and tagging each cell takes .5 seconds. The entire script takes several hours to complete.</p>

<p>I can post the inner loop code, but I'm not sure if SO is supposed to be generic or specific. I'll let the mob decide.</p>

<p>[edit]
The code builds a list (prior to this loop) which contains one item per row in the table. There is also a list containing one string for each column in the table. For each cell, the program creates an XML element and an XML tag by concatenating the items in the [row]/[column] positions of the two lists. It also associates the text in that cell to the newly-created element.</p>

<p>I'm completely new to AppleScript so some of this code is crudely modified from Adobe's samples. If the code is atrocious I won't be offended.</p>

<p>Here's the code:</p>

<pre><code>repeat with columnNumber from COL_START to COL_END

    select text of cell ((columnNumber as string) &amp; ":" &amp; (rowNumber as string)) of ThisTable

    tell activeDocument

        set thisXmlTag to make XML tag with properties {name:item rowNumber of symbolList &amp; "_" &amp; item columnNumber of my histLabelList}

        tell rootXmlElement

            set thisXmlElement to make XML element with properties {markup tag:thisXmlTag}

        end tell

        set contents of thisXmlElement to (selection as string)

    end tell

end repeat
</code></pre>

<p>EDIT: I've rephrased the question to better reflect the correct answer.</p>

[{'answer_id': 11580, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>I can post the inner loop code, but I'm not sure if SO is supposed to be generic or specific. I'll let the mob decide.</p>\n</blockquote>\n\n<p>The code you post as an example can be as specific as you (or your boss) is comfortable with - more often than not, it's easier to help you with more specific details.</p>\n"}, {'answer_id': 11581, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 0, 'selected': False, 'text': "<p>If the inner loop code is a reasonable length, I don't see any reason you can't post it.  I think Stack Overflow is intended to encompass both general and specific questions.</p>\n"}, {'answer_id': 28629, 'author': 'Mike Heinz', 'author_id': 1565, 'author_profile': 'https://Stackoverflow.com/users/1565', 'pm_score': 1, 'selected': False, 'text': '<p>The problem is almost certainly the select. Is there anyway you could extract all the text at once then iterate over internal variables?</p>\n'}, {'answer_id': 50651, 'author': 'Eric', 'author_id': 5277, 'author_profile': 'https://Stackoverflow.com/users/5277', 'pm_score': 0, 'selected': False, 'text': "<p>Are you using InDesign or InDesign Server? How many pages is your document (or what other information can you tell us about your document/ID setup)?</p>\n\n<p>I do a lot of InDesign Server development. You could be seeing slow-downs for a couple of reasons that aren't necessarily code related.</p>\n\n<p>Right now, I'm generating 100-300 page documents almost completely from script/xml in about 100 seconds (you may be doing something much larger).</p>\n"}, {'answer_id': 230204, 'author': 'JPLemme', 'author_id': 1019, 'author_profile': 'https://Stackoverflow.com/users/1019', 'pm_score': 2, 'selected': True, 'text': "<p>I figured this one out.</p>\n\n<p>The document contains a bunch of data tables. In all, there are about 7,000 data points that need to be exported. I was creating one root element with 7,000 children.</p>\n\n<p>Don't do that. Adding each child to the root element got slower and slower until at about 5,000 children AppleScript timed out and the program aborted.</p>\n\n<p>The solution was to make my code more brittle by creating ~480 children off the root, with each child having about 16 grandchildren. Same number of nodes, but the code now runs fast enough. (It still takes about 40 minutes to process the document, but that's infinitely less time than infinity.)</p>\n\n<p>Incidentally, the original 7,000 children plan wasn't as stupid or as lazy as it appears. The new solution is forcing me to link the two tables together using data in the tables that I don't control. The program will now break if there's so much as a space where there shouldn't be one. (But it works.)</p>\n"}]
['https://Stackoverflow.com/questions/11574', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1019/']