-
1. Re: How do you revise/modify a single value of an XML element with Extendscript?
iamwickedtall1 Oct 25, 2014 11:40 AM (in response to iamwickedtall1)xbytor2 Not that you need to solve all my problems, but I read in some forums you may have experience with the above question.
-
2. Re: How do you revise/modify a single value of an XML element with Extendscript?
xbytor2 Oct 25, 2014 2:31 PM (in response to iamwickedtall1)I stripped your code down to bare essentials. I was able to insert dateRun into the XML without any problems. Here's my code.
function readXML(toRead){ toRead.open('r'); var xmlStr = toRead.read(); toRead.close(); return new XML(xmlStr); }; var theFile = File(Folder.userData + "/Image Processor Pro.xml"); // Assume the file exists var xmlReadObj = readXML(theFile); $.writeln(xmlReadObj.toXMLString()); xmlReadObj.dateRun = "test"; $.writeln(xmlReadObj.toXMLString());Note that you'll have to have ESTK up and running to see the $.writeln output.
-
3. Re: How do you revise/modify a single value of an XML element with Extendscript?
iamwickedtall1 Oct 25, 2014 2:49 PM (in response to xbytor2)I am seeing it successfully run into the console, but its not recording to the file. Do I need to just rewrite the whole file again? ETSK docs sounded like I could just update the one line.
-
4. Re: Re: How do you revise/modify a single value of an XML element with Extendscript?
xbytor2 Oct 25, 2014 3:02 PM (in response to iamwickedtall1)You do need to write xmlReadObj.toXMLString() to file to update it with the new value. Here's how I do it in xtools/xlib/stdlib.js:
Stdlib.writeXMLFile = function(fptr, xml) { var rc; if (!(xml instanceof XML)) { Error.runtimeError(19, "xml"); // "Bad XML parameter"; } var file = Stdlib.convertFptr(fptr); file.encoding = "UTF8"; rc = file.open("w", "TEXT", "????"); if (!rc && Stdlib.IOEXCEPTIONS_ENABLED) { Error.runtimeError(Stdlib.IO_ERROR_CODE, Stdlib.fileError(file)); } // unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF" // optional //file.write("\uFEFF"); file.lineFeed = "unix"; file.writeln('<?xml version="1.0" encoding="utf-8"?>'); rc = file.write(xml.toXMLString()); if (!rc && Stdlib.IOEXCEPTIONS_ENABLED) { Error.runtimeError(Stdlib.IO_ERROR_CODE, Stdlib.fileError(file)); } rc = file.close(); if (!rc && Stdlib.IOEXCEPTIONS_ENABLED) { Error.runtimeError(Stdlib.IO_ERROR_CODE, Stdlib.fileError(file)); } return file; };The error handling code is in there because it's easier to track down IO problems when they occur.
-
5. Re: Re: How do you revise/modify a single value of an XML element with Extendscript?
iamwickedtall1 Oct 25, 2014 3:32 PM (in response to xbytor2)Got it. Thanks!

