Applescript with XML ... help please

unfortunately when searching the forums the minimum number of letters a word can have is 4, so I was unable to find any info on XML in applescript.

I am pretty good at applescript but I am completely new to XML.

I am trying to write a script that can change a specific property that appears multiple times through out an xml document.

the xml looks something like this:


0 0 0 0 0 16384 524304 0 15 _____________

The xml document is filled with these elements and I want to change the property between 1 and 0 depending on a spreadsheet.

I plan on having a spreadsheet that has a column for each scenenode, in this example “T4-highlight” and the rows beneath the columns will be filled with 1s and 0s.

any help would be greatly appreciated.

thanks,

ryan

I’m not quite sure how to answer this. The “depending on a spreadsheet” makes it more difficult to say. There are a couple of XML Scripting Additions available, one from Satimage (makers of Smile).

I’m mostly a FileMaker developer, who also dabbles in AppleScript. FileMaker supports exporting XML, with transformations via an XSL stylesheet. So, instead of using a spreadsheet you could have the data in FileMaker and export the entire xml file in one shot. FileMaker also imports spreadsheet data (csv, tab, Excel). I’m not quite sure how you’d do the stylesheet however, like where the other data is coming from. If it’s in the spreadsheet, then it would not be a problem to export the whole thing, creating elements and filling in the data. It would not be easy, but it would be entirely doable.

If on the other hand you just want to a kind of Find and Replace on the existing xml, that’s kind of different. That would be more a job of reading the values from the spreadsheet, finding which one to change, and changing it. Likely one of the AppleScript XML Scripting Additions could do this. I’ve never done such a thing.

find and replace on an xml document is exactly what I want to do.

if anyone knows how to do xml find and replace in applescript, could you please point me in the right direction?

thanks,

ryan

You will probably need the XML handling osaxen from Late Night Software.

http://www.latenightsw.com/freeware/

Well there are two ways without any outside additions that I can think of. First, if you just want to do a global find&replace across the entire doc you can get away with just using the typical text item delimiters search & replace routine. The second option is doing a toggle of a particular key. For this you need to know the general layout of the xml files in question and involves using offset to find your values and the toggle.