• 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: XML script library?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML script library?


  • Subject: Re: XML script library?
  • From: Alex Zavatone <email@hidden>
  • Date: Tue, 03 Mar 2015 09:53:03 -0500

Looking at this problem from the Objective-C side of things, the flow of operations would seem straightforward to read it into memory, serialize into a dictionary, then save the dictionary out to a plist.

Sent from my iPad. Please pardon typos.

On Mar 3, 2015, at 9:35 AM, Jörgen Stahle <email@hidden> wrote:

Can I ask you for one more little thing, Shane?
It would be useful to have the option to save the xml directly to file, instead of returning it. I guess it is just a question of changing the last line in the makeXMLDocWithRecord. (I’ve tried, by stealing from your Json export handler, with no success.)
Jörgen

2 mar 2015 kl. 03:10 skrev Shane Stanley <email@hidden>:

on makeXMLDocWithRecord:theRecord
-- make root element
set rootElement to current application's NSXMLNode's elementWithName:"character"
-- make XML document
set theXMLDocument to current application's NSXMLDocument's alloc()'s initWithRootElement:rootElement
theXMLDocument's setDocumentContentKind:(current application's NSXMLDocumentXMLKind)
theXMLDocument's setStandalone:true
theXMLDocument's setCharacterEncoding:"UTF-8"
-- make dictionary from record
set anNSDictionary to current application's NSDictionary's dictionaryWithDictionary:theRecord
-- add children to root element
its addChildTo:rootElement withDictionary:anNSDictionary
-- return as string with whatever formatting options you want
return (theXMLDocument's XMLStringWithOptions:(current application's NSXMLNodePrettyPrint)) as text
end makeXMLDocWithRecord:

on addChildTo:parentElement withDictionary:theDict
set theKeys to theDict's allKeys() as list
repeat with i from 1 to count of theKeys
set theKey to item i of theKeys
set theValue to (theDict's objectForKey:theKey)
set newElement to (current application's NSXMLNode's elementWithName:theKey)
(parentElement's addChild:newElement)
if (theValue's isKindOfClass:(current application's NSDictionary)) as boolean then
(its addChildTo:newElement withDictionary:theValue)
else
(newElement's setObjectValue:theValue)
end if
end repeat
end addChildTo:withDictionary:




       
<image001.png>

JÖRGEN STAHLE

Sidproduktionsansvarig
IT

TT Nyhetsbyrån

105 12 Stockholm
+46 70 372 44 46
tt.se

_______________________________________________
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
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: 
 >Re: XML script library? (From: Shane Stanley <email@hidden>)
 >Re: XML script library? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: XML script library?
  • Next by Date: Re: XML script library?
  • Previous by thread: Re: XML script library?
  • Next by thread: Re: XML script library?
  • Index(es):
    • Date
    • Thread