Import multiple XML files not working
I'm working on a quiz booklet where each question is in its own xml file, so I'm trying to import multiple XML files into a single InDesign document. I'm attempting to append each XML inside the Root element, so I can just place the root into a text frame and have all the questions in a single story. My code is below, but it errors out and I can't figure out why.
var myDoc = app.activeDocument;
var myTransform = File.openDialog("Select XSL transform");
var myXMLImportPreferences = myDoc.xmlImportPreferences;
myXMLImportPreferences.allowTransform = true;
myXMLImportPreferences.createLinkToXML = true;
myXMLImportPreferences.ignoreUnmatchedIncoming = false;
myXMLImportPreferences.ignoreWhitespace = false;
myXMLImportPreferences.importCALSTables = true;
myXMLImportPreferences.importStyle = XMLImportStyles.appendImport;
myXMLImportPreferences.importTextIntoTables = false;
myXMLImportPreferences.importToSelected = true;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.repeatTextElements = false;
myXMLImportPreferences.transformFilename = myTransform;
var xmlFolder = Folder.selectDialog("Select the folder with the XML files");
if(xmlFolder !=null){
var xmlFiles = GetSubFolders(xmlFolder); //returns array of all xml files in xmlFolder and its subfolders
}
main();
function main(){
for(var x = 0; x < xmlFiles.length; x++){
$.writeln(xmlFiles
.name); if(xmlFiles
!= null){ app.select(myDoc.xmlElements.item(0));
myDoc.importXML(xmlFiles
); }
}
}
The error occurs on line 30, and all Extendscript does is highlight that line and display "importXML" where the error would normally appear. If I manually import the XML files, everything works. I don't have any issues with the xml or the transform. This code worked once, but only once, and every time since then, I get the same weird "importXML" error.
Any ideas?