• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Iterating over items in a record, possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Iterating over items in a record, possible?


  • Subject: Re: Iterating over items in a record, possible?
  • From: Emmanuel Levy <email@hidden>
  • Date: Fri, 9 Jan 2009 11:21:07 +0100

At 5:08 AM -0500 1/9/09, Ken Tozier wrote:
Hi

I'm writing a general purpose script to convert a complex nested record into an Apple "plist" and can't figure out how to iterate over items in a record if I don't know any of the record keys beforehand. For example, given the following record, I'd like to iterate the items and get the keywords and the values something like the following pseudo-code

set aRecord to {height: 100, width: 100, originX: 10, originY: 10}

set xml to "<dict>" & return
repeat with anItem in aRecord
	set itemKey to keyword of anItem
	set itemValue to value of anItem
	set xml to xml & tab & "<key>" & itemKey & "</key>" & return
	set xml to xml & tab & "<string>" & itemValue & "</string >" & return
end
set xml to xml & "</dict>"

Keep in mind, I have no control over the keywords and I actually don't know what they are. They are whatever the target application returns for a query.

In Smile, or with XMLLib.osax, that's fairly simple:

set aRecord to {height: 100, width: 100, originX: 10, originY: 10}
set p to plistnew aRecord

you may run then:

set xml to plistgetxml p

-->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<dict>
<key>height</key>
<integer>100</integer>
<key>originx</key>
<integer>10</integer>
<key>originy</key>
<integer>10</integer>
<key>width</key>
<integer>100</integer>
</dict>
</plist>


Emmanuel
_______________________________________________
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
References: 
 >Iterating over items in a record, possible? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: count pages in PDF on OS 10.4
  • Next by Date: Re: Assigning Quark color spec - Tiger->Leopard
  • Previous by thread: Iterating over items in a record, possible?
  • Next by thread: Calling a C Subroutine
  • Index(es):
    • Date
    • Thread