Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML - System Events vs XMLlib



On 30 Aug 2007, at 14:47, Wayne Melrose wrote:

Thanks fo the reply.

No problem.


Just out of curiosity though, I have the xml as a stored variable (it was never a text file as it is not actually a plist but xml in the form of a plist.) is there a way to "tell contents of VAR_name"?

tell application "System Events"
-- make new plist item
set plist to make new property list item with data "<?xml version= \"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http:// www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>keyname</key>
<integer>8</integer>
<key>creation</key>
<string>2007:06:12 20:13:52</string>
<key>happy</key>
<false/>
</dict>
</plist>
"
-- do stuff with it, e.g.
set val to properties of property list items of plist
-- dispose plist item when done
delete plist
end tell
val
--> {{kind:boolean, name:"happy", class:property list item, value:false},
{kind:string, name:"creation", class:property list item, value:"2007:06:12 20:13:52"},
{kind:number, name:"keyname", class:property list item, value:8}}



This, as we can see is pretty simple too.. But if there were 100 or so properties in the xml.. There's no real way of referencing them out into (for example) an applescript record is there?

This appears to do what you want, caveat that the lack of official System Events documentation means that I've no idea if this is officially supported behaviour or not:


tell application "System Events"
set plist to make new property list item with data "<?xml version= \"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http:// www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>keyname</key>
<integer>8</integer>
<key>creation</key>
<string>2007:06:12 20:13:52</string>
<key>happy</key>
<false/>
</dict>
</plist>
"
set plist2 to make new property list item with data plist
set val to value of plist2
delete plist
delete plist2
end tell
val
--> {happy:false, creation:"2007:06:12 20:13:52", keyname:8}


HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: XML - System Events vs XMLlib (From: has <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.