Re: XMLlib library - somewhat.
Re: XMLlib library - somewhat.
- Subject: Re: XMLlib library - somewhat.
- From: Emmanuel LEVY <email@hidden>
- Date: Fri, 02 May 2014 19:59:24 +0200
Related, FWIW: our XMLLib.osax Scripting Addition includes handy PlistToJSON and PlistFromJSON commands.
Emmanuel
On May 2, 2014, at 4:50 PM, Alex Zavatone wrote:
> This touches on another issue that I run into into on native iOS frequently and also relates to XIB file structure now that it is new, improved and finally deterministic.
>
> Internal dictionaries and arrays (NSDictionary and NSArray) can be serialized to disk at .plist files. Plist files are really specialized XML files in a format.
>
> Today, we mainly read and send data from http servers in XML and JSON format, with both being rather friendly with key value pairs.
>
> It seems that we have three main data file formats that it would be nice to be able to read and write and convert back and forth that can be represented in memory as NSArrays, NSDictionaries in Objective-C and in AppleScript as lists and records.
>
> JSON
> XML
> Plist
>
> Though many times complicated XML files require a defining schema to be properly read and serialized, the plist structure is self defining.
>
> I'm messing around with creation of some rapid development tools for iOS and after seeing the internal memory structures and disk based file formats and seeing this response to the thread, it sure seems that a library for AppleScript and for Cocoa to convert between the differing file formats would be a terribly useful thing to have.
>
> In Objective-C Cocoa, writing or reading an NSDictionary or NSArray to a pList is 1 line of code.
> JSON can also be read and serialized to a dict without too much fuss using NSJSONSerialization.
> Simple XML (that doesn't require a schema) can also be handled easily as Shane shows below.
>
> I don't know if I'll have the time to put into all of this, but if anyone is inclined to start some Objective-C and some AppleScript and/or some ASOC, I'd be glad to help. It sure would be useful for everyone.
>
> Cheers.
>
>
> On Apr 26, 2014, at 8:57 AM, Shane Stanley wrote:
>
>> On 26 Apr 2014, at 7:43 am, Wayne Melrose <email@hidden> wrote:
>>
>>> Can we call this closed now?
>>
>> Not quite. In case they come to their senses, here's some sample ASObjC code for doing an XPATH query. Results are returned as an XML object containing matching nodes, and a list of any matching attributes.
>>
>> use framework "Foundation"
>>
>> on extractFrom:thePath matchingXPath:theQuery
>> set aURL to current application's |NSURL|'s fileURLWithPath:thePath -- make NSURL
>> set theXMLDoc to current application's NSXMLDocument's alloc()'s initWithContentsOfURL:aURL options:0 |error|:(missing value) -- make XMLDoc
>> set attStrings to {} -- where attributes will be stored
>> set theXMLOutput to current application's NSXMLElement's alloc()'s initWithName:"output" -- found nodes added to this
>> set {theResults, theError} to (theXMLDoc's nodesForXPath:theQuery |error|:(reference)) -- query
>> if theResults is not missing value then
>> repeat with aNode in (theResults as list)
>> aNode's detach() -- need to detach first
>> if aNode's |kind|() as integer = current application's NSXMLAttributeKind then -- see if it's an attribute or node
>> set end of attStrings to (aNode's stringValue()) as text
>> else
>> (theXMLOutput's addChild:aNode) -- add node
>> end if
>> end repeat
>> return {(theXMLOutput's XMLStringWithOptions:(current application's NSXMLNodePrettyPrint)) as text, attStrings} -- change options to suit
>> else
>> return missing value
>> end if
>> end extractFrom:matchingXPath:
>>
>> No plug-ins, nothing up your sleeves...
>>
>> --
>> Shane Stanley <email@hidden>
>> <www.macosxautomation.com/applescript/apps/>
>>
>> _______________________________________________
>> 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
_______________________________________________
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