Skip to main content
frameexpert
Community Expert
Community Expert
October 4, 2013
Answered

Writing XML Object to a File

  • October 4, 2013
  • 1 reply
  • 651 views

Hi, I am using InDesign JavaScript to make an XML object in memory. When my script is done, I want to write the XML to a file. When I run the code below, the file is created, but the XML is not written to the file. Any help would be appreciated. Thanks. Rick

#target indesign

var partsMap = <partsMap />;

savePartsMap (partsMap);

function savePartsMap (partsMap) {

   

    var partsFile;

   

    // Make a File object for the parts map XML file.

    partsFile = new File("E:\\Test.xml");

    // Open the map file.

    partsFile.open("w");

    partsFile.write(partsMap);

    partsFile.close();

}

This topic has been closed for replies.
Correct answer absqua

Add partsFile.encoding = 'UTF-8'; right after your File instantiation.

I'm not sure but you also might want to write partsMap.toXMLString() instead of the partsMap.toString() you're implicitly writing.

Jeff

1 reply

absquaCorrect answer
Inspiring
October 4, 2013

Add partsFile.encoding = 'UTF-8'; right after your File instantiation.

I'm not sure but you also might want to write partsMap.toXMLString() instead of the partsMap.toString() you're implicitly writing.

Jeff