Re: XML to AppleScript Record
Re: XML to AppleScript Record
- Subject: Re: XML to AppleScript Record
- From: "Steven D. Majewski" <email@hidden>
- Date: Tue, 4 Mar 2008 10:57:50 -0500
On Mar 3, 2008, at 2:24 PM, Stockly, Ed wrote:
Before I go about reinventing the wheel, I have a question for the
list.
Has anyone tried converting XML data to an appleScript record,
using the xml
tags as record labels.
In other words,
...
Should translate as:
{root:{{xmlDataFormat:{version:"1.1:"}}, {dataTagFoo:
{dataTagBar:"Data"}},
{dataTagMore:"More Data Data"}}}
I couldn't see how to do this with any of the XML osax or system
events. Am
I missing something?
[ I'll try to stiffle the impulse to rant about either AppleScript,
XML processing,
or the union or intersection of the two, and instead try to be
helpful. ]
I note that the record literal you want looks a lot like JSON notation.
There are XML -> JSON converters in Javascript like BadgerFish
<http://badgerfish.ning.com/>th
You could modify the javascript to make the JSON output more exactly
like Applescript
record literals ( loose the quotes around the record keys, for
example. ), and script
Safari to load the xml and do a 'do javascript' to process the xml
into something more
easily digestible by Applescript.
Or, since XSLT is the simplest way to process XML, and OSX has
'xsltproc' installed,
use it to preprocess the XML into an Applescript record literal.
Googling for "xslt json"
brings up this Google Code project: <http://code.google.com/p/
xml2json-xslt/>
( It has two stylesheets: one that processes XML into "standard"
JSON, and another that
creates a more directly javascript digestable one -- the
javascript one is already
closer to the Applescript syntax. )
Preprocess you xml via a 'do shell script "xsltproc xml2as.xslt " &
xmlfile '
and eval the output as a applescript literal.
Another variant way of processing XML ( not what Ed asked for, but
perhaps answering
one of the followup questions ) might be to use Safari to load and
parse the XML into
a DOM document, and send it little 'do javascript' snippets of an
access function
that would make 'drilling down' into the DOM a little easier syntax.
( Sort of an
XPATH processor. )
I know those sound kind of round-about solutions, but that seems to
be what's being asked for
in this thread: someway to process XML other than the usual system
events or XML OSAX.
-- Steve Majewski
_______________________________________________
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