Re: Aaaarrrggghhh XML!
Re: Aaaarrrggghhh XML!
- Subject: Re: Aaaarrrggghhh XML!
- From: Roger Howard <email@hidden>
- Date: Wed, 23 Feb 2005 12:19:05 -0800
On Feb 23, 2005, at 10:05 AM, Martin Orpen wrote:
on 23/2/05 4:56 pm, Roger Howard at email@hidden wrote:
I've done limited work with AppleScript and XMP; while XML Tools
works,
it does get a bit heady with documents like XMP. What I found easiest
was to transform the XMP using a style sheet (XSLT), and then work
with
that (either using XML Tools, or even by transformaing the XMP to a
simpler, non-XML format). I'm not sure if I've got a copy of any of
these style sheets here, but I'll dig em up if I can.
Cheers.
What I'm after is something like this kind of output:
Nikon EXIF data:
ExposureTime: 1/750
ShutterSpeedValue: 9550747/1000000
FNumber: 71/10
ApertureValue: 5655638/1000000
ExposureProgram: 2
DateTimeOriginal: 2005-02-07T08:11:22Z
ExposureBiasValue: 0/1
MaxApertureValue: 43/10
MeteringMode: 5
FocalLength: 90/1
FocalLengthIn35mmFilm: 135
ISOSpeedRatings:
ISO: 200
Flash:
Fired: False
Return: 0
Mode: 0
Function: False
RedEyeMode: False
I can easily grab the info from a single layer of the xml, but as soon
as I
get to the nested stuff like ISOSpeedRatings and Flash the script will
fail.
Exactly, which is why I used XSLT in the past - it's the perfect
language for extracting (and reformatting) data from XML documents,
transforming them into another format (which is what XSLT is for). You
can transform into a simple text format like the above just as easily
as you could transform into another XML format (actually, easier
really).
Also, Photoshop files can carry a large amount of metadata with lots of
different styles and data types, so I need a flexible solution.
XSLT... otherwise you'll be doing a ton of conditional coding in
AppleScript, dealing with all the varieties of XMP you'll encounter.
This seems like the sort of thing that should be handled by the OS
pretty
easily - just like any plist - rather than having to loop through every
element to see how deep the data is.
But plist is a specialized XML format, and it's not RDF (as far as I
know)... XMP is also specialized, and has a different structure (being
based on RDF). It's all XML of course, but that helps us about as much
as knowing two documents are both ASCII!
Anyway, dealing with somewhat arbitrary XML structures is something
that is dealt with in xslt/xpath very well - you can even use xpath
statements directly from AppleScript using XSLT Tools - for me, this is
often easier than using XML Tools and the AppleScript record structures
that it generates.
I was sure that I'd seen an example in the Developer documentation, but
can't find anything relevant when I search :-(
I don't know how much RDF/XML is used in OSX... plists aren't RDF.
Anyhow, for any XML formatting problems, XSLT is pretty well suited -
though it's not necessarily for the easily dissuaded. And depending on
complexity of your needs, it's sometimes reasonable to write your own
code to parse some specific data from XML - but once you start dealing
with more than very simple XML documents, I find using tools like xpath
much easier (not that XSLT or Xpath is easy!).
Anyway, I've done exactly (well almost) what you've done above, for
moving data between XMP sidecars and SQL databases, and I ended up
making judicious use of XPath expressions. Then again, I bet some
people (on this list!) might use regular expressions instead!
-R
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden