Re: XML Editing - set Value with System Events
Re: XML Editing - set Value with System Events
- Subject: Re: XML Editing - set Value with System Events
- From: Doug McNutt <email@hidden>
- Date: Mon, 09 Apr 2012 13:02:48 -0600
At 11:04 -0500 4/9/12, Luther Fuller wrote:
>On Apr 7, 2012, at 7:01 PM, email@hidden wrote:
>
>> Hi I am trying to modify an element value in an XML.
>> I am using the base script below but the value is not being written to the file.
>
>In a recent post, I mentioned that I had successfully read an .xml file using commands from System Events' Property List Suite. (As if the file were a .plist file.) I don't know if you can write an .xml file this way. It might be worth a try.
>
>
Depending on just how general you need, or want, to be. . .
XML files are TEXT and they are closely equivalent to HTML for which text editors work just fine. They also open nicely in modern browsers.
At 10:01 +1000 4/8/12, email@hidden wrote:
><?xml version="1.0" encoding="UTF-8" ?>
><ImageTransformList>
> <MediaRef>/media/dbone/Left/18_01/1920x1080/12345.tiff</MediaRef>
> <RefId>12345.tiff</RefId>
></ImageTransformList>
In a text editor that doesn't subtly force you into RTF or some other word processing format (BBedit, and Text Wrangler come to mind) you could probably do a replace with a regular expression.
s/<ImageTransformList>\n\t <MediaRef>(.*) </MediaRef>/<ImageTransformList>\n\t <MediaRef>$r </MediaRef>/;
The syntax varies a bit with the text editor you choose to use and the single tab used in your example might not be exactly the white space in the file. Just how fancy you want to get depends on how often you want to use the substitution and how much other XML file structures might be different.
Above \n and \t are the line end and tab. (.*) is the old file spec that is to be replaced. $r is your replacement. That nomenclature comes from perl. UNIX sed is quite similar. Both are available but not AppleScriptable. You would have to use "do shell script".
You could try making the change with a text editor just to be sure everything works. You might even be able to record an AppleScript to do it.
--
--> A fair tax is one that you pay but I don't <--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden