Friday, November 16, 2018

#1 2018-09-14 10:38:00 pm

technomorph
Member
Registered: 2017-12-14
Posts: 72

Setting Framework Variables

using the script from :
http://piyocast.com/as/archives/790

Applescript:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "XmlToDictKit" --https://github.com/nicklockwood/XMLDictionary

set aFile to POSIX path of (choose file)
set aURL to current application's |NSURL|'s fileURLWithPath:aFile
set xmlString to current application's NSString's alloc()'s initWithContentsOfURL:aURL encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
if xmlString = missing value then return false
set xmlDoc to (current application's NSDictionary's dictionaryWithXMLString:xmlString) as record

in the framework "XmlToDictKit" the default option is set so that attributes are named
with a "_" in front of them for their dictionary key.

I would like to change this default.


from the readme have found:

Applescript:

@property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;

This property controls how XML attributes are handled.
The default is XMLDictionaryAttributesModePrefixed meaning that attributes will be included in the dictionary, with an _ (underscore) prefix to avoid namespace collisions.
Alternative values are XMLDictionaryAttributesModeDictionary, which will place all the attributes in a separate dictionary, XMLDictionaryAttributesModeUnprefixed, which includes the attributes without prefix (which may cause collisions with nodes) and XMLDictionaryAttributesModeDiscard, which will strip the attributes.

from the framework header (XMLDictionary.h):

Applescript:

typedef NS_ENUM(NSInteger, XMLDictionaryAttributesMode)
{
XMLDictionaryAttributesModePrefixed = 0, //default
XMLDictionaryAttributesModeDictionary,
XMLDictionaryAttributesModeUnprefixed,
XMLDictionaryAttributesModeDiscard
};

I would like to via my applescript set the Framework XMLDictionaryAttributesMode to XMLDictionaryAttributesModeUnprefixed

can someone guide me on how to accomplish this via Applescript?
Or do I need to hardcode the framework header to set the default?

thanks

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)