populateTemplate() and loadXMLAnswers don't get along very well. If a survey uses populateTemplate to add questions that weren't originally there, when you load them back in loadXMLAnswers may complain that the question doesn't exist.
I've done what I can to solve this problem. loadXMLAnswers does this:
while(hasAnswersForExistingQuestions(answerMap)) {
answerExistingQuestions(answerMap);
}
But this won't solve every problem. For example, if you have a script that says once you answer a certain question 20 times a new template gets populated, there's no way this script can solve this problem. It can also be as simple as a question that only shows up if you take the survey later than 5pm. What happens if you try to load the answers at 1pm the next day?
I've half-thought of a couple of solutions to this problem. The first is that we could add more details to the result.xml file. Maybe include the order or how many times each question was answered.
The other is to add a new script called loadScript that gets passed an answerMap and is responsible for using it to load its own state. Issues about this idea: does the loadScript get executed AND the code mentioned above or are they mutually exclusive?