The reason I ask is I’d like to replace just one element in an XML-like document. I say XML-like because I have been unable to edit it using NSXMLDocument. That is probably because it is not a typical XML. It is a project file for Apple Motion. My work around was simply reading the file as NSString then creating an element using NSXMLElement, XMLStringWithOptions and NSXMLNodePrettyPrint. Then I simply use stringByReplacingOccurrencesOfString to replace the element. Using this method I can escape structures that conflict with XML format (such as <>), but it does nothing with special characters.
That script is amazing and it seems to work fine. But I’m still getting the same problem when I output the file.
Is the problem with how I’m saving the file?
Here’s what I have:
on writeMotionFile(theFileManager, templatePath, destinationFile, thisSource)
set thisSourceEntityEncoded to current application's SMSForder's encodedXMLFrom:thisSource
set theTemplate to current application's NSString's stringWithContentsOfFile:templatePath encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
set theTemplate to theTemplate's stringByReplacingOccurrencesOfString:"[insert text here]" withString:thisSourceEntityEncoded
theTemplate's writeToFile:destinationFile atomically:true
end writeMotionFile
In case you are wondering, this project accomplishes what I set out to do in this post http://macscripter.net/viewtopic.php?id=43801 back in April. By manipulating both clipboard data and the original Apple Motion template files, I can automate all sorts of things in Final Cut Pro X.