Re: How to work with XML data using System Events?
Re: How to work with XML data using System Events?
- Subject: Re: How to work with XML data using System Events?
- From: has <email@hidden>
- Date: Fri, 4 Nov 2005 21:18:26 +0000
Paul Berkowitz wrote:
> > But anyway, when working with plists it's simpler to use SE's dedicated PList
>> Suite, e.g.:
>
>System Events in OS 10.4.3 has both a "Property List Suite" (I assume that's
>what you mean by "PList Suite")
Yes. Typo.
> and an "XML Suite". Are these the same in 10.4.2?
Same in all 10.4.x releases.
>(It's a bit odd that you can't get 'property list item' out of any
>property or element of 'property list file', and can't get 'XML data' out of
>any property or element of 'XML file'.
'property list file' and 'XML file' are subclasses of 'file', not 'property list item' and 'XML data'. Both add a single property, 'contents', which provides a relationship to the entire XML document. To get the root element of that XML document (which is the starting point you usually want), you'd use:
XML element 1 of contents of XML file "path:to:file.xml"
There's the usual amount of Cocoa stupidity to wade through (e.g. properties that return None instead of 'missing value' when they don't contain a value) along with the usual lack of fine detail and general guidance from the dictionary-based documentation, but the containment structure itself is quite logical [1].
> > Unfortunately, the above code doesn't work when I tried it OMM (10.4.2) as the
>> line marked '[1]' returns a reference to the wrong element. This appears to be
>> a bug in System Events; don't know if it's fixed in 10.4.3, but if anyone can
>> reproduce it there then they're welcome to file it.
>
>It's still there. Since it's returning 'property list item 2 of property
>list item "untitled"', instead of 'property list item 1 of property list
>item "untitled"', which is the correct one, it looks to me as if there's
>been an incorrect conversion of what was expected to be a 0-based list to a
>1-based list whereas it was 1-based all along and didn't need converting. Or
>something like that.
Could be; off-by-one errors are easily made, especially when bridging between systems that use 0-indexing (Cocoa) and 1-indexing (Apple events). Although the second such reference in my original code had no such problems. Probably best just to file a bug report demonstrating the problem and let the Apple engineers figure it out. (I don't care enough about this particular bug to bother reporting it myself, but more concerned users are welcome to do so.)
>One could work around that until the bug is fixed ;-) :
I believe I already did. :)
has
[1] Although it could be improved by defining an explicit 'XML document' class and defining that as the document's root, rather than just coopting an 'XML data' element which is less than self-explanatory. An 'XML document' object could also provide a means to access to information such as XML version and encoding, and the document's doctype, which is not available in the current arrangement.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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