5 Replies Latest reply: Oct 25, 2014 3:32 PM by iamwickedtall1 RSS

    How do you revise/modify a single value of an XML element with Extendscript?

    iamwickedtall1 Community Member

      I have created the below script to create an XML settings file, that will be recalled upon every execution of a script. I am able to successfully execute the script and get it created, but I'm not so sure how to modify the values contained with in. As far as the Extendscript reference is concerned, I should simply be able to use the following example "bookstoreXML.book[1].year = 1901;" or in my case "xmlReadObj.dateRun = "TEST"". I'm not quite sure where this goes however, I've tried opening the file for writing, but that just erases the whole file and replaces with "TEST". I've also looked up examples, and found examples where the file is not opened, but rather just read. Is it possible to write this way? Do I need to use replace()? Any examples would be appreciated.

       

      function readXML(toRead){

      toRead.open('r')

      var xmlStr = toRead.read()

      toRead.close()  

      return xmlReadObj = new XML(xmlStr)

      }

       

      slash = "\\"

       

      function makeFolder(funcFolder) {

      makeFolderPath = Folder(funcFolder);

      if (!makeFolderPath.exists) makeFolderPath.create();

      }

      theFolder = Folder.userData.fsName+slash+"Script Settings"

       

      makeFolder(theFolder)

      theFile = File(theFolder+ slash+ "LSN_settings.xml")

      if (!theFile.exists){

      var fsnSettingsStructure = new XML ("\

      <fsnSettings>\

          <dateRun>2014</dateRun>\

      </fsnSettings>");

      xmlFile = new File(theFile);

      xmlFile.open('w','XML','????')

      xmlFile.write(fsnSettingsStructure);

      xmlFile.close()

      }

      else {

      readXML(theFile)

      xmlReadObj.dateRun = "TEST"

      }