Re: XML generation details (was Re: ASObjC alloc and object creation)
Re: XML generation details (was Re: ASObjC alloc and object creation)
- Subject: Re: XML generation details (was Re: ASObjC alloc and object creation)
- From: Shane Stanley <email@hidden>
- Date: Tue, 30 Jan 2018 10:33:49 +1100
On 30 Jan 2018, at 1:25 am, Jean-Christophe Helary
<email@hidden> wrote:
>
> set theData to theProject's XMLDataWithOptions:((current application's
> NSXMLDocumentTidyXML) + (get current application's NSXMLNodePrettyPrint))
> theData's writeToFile:"/path/to/file" atomically:true
>
> 1) What I get from the Xcode documentation for XMLDataWithOptions is:
>
> One or more options (bit-OR'd if multiple) to affect the output of the
> document; see Constants <apple-reference-documentation://hc1_X8m4hw> for the
> valid output options.
>
> :-) I'm glad I know English...
AppleScript users spend a lot of time complaining about poor documentation. You
should be pleased to see we are not alone ;-)
> So that "+" between the two options is the bit-OR thing?
Right. Bit-OR-ing means if one OR other value's particular bit is true, the bit
for that result is true -- so 0001 and 010 gives 0011. That's the same as 1 + 2
= 3 in the integer world.
> Also, when I click on the "Constants" link I don't find NSXMLDocumentTidyXML
> nor NSXMLNodePrettyPrint but they *are* in the doc, under NSXMLNodeOptions,
> which is confusing...
Yes and no. You should be seeing this declaration:
> - (NSData <dash-apple-api://load?request_key=hcszIi2z4T&language=occ>
> *)XMLDataWithOptions:(NSXMLNodeOptions
> <dash-apple-api://load?request_key=hcQrR9ugCn&language=occ>)options;
That's telling you that the options are NSXMLNodeOptions, and in fact the word
itself is a link to them. You will also see it if you use code-completion.
> But in any case, what I get there is:
>
> NSXMLDocumentTidyXML = 1UL << 10,
> NSXMLNodePrettyPrint = 1UL << 17,
>
> Which really doesn't mean much to me.
That's just giving the underlying binary values, which don't matter to you. The
first just says that the 10th bit from the right is set. If you want to know
their integer values, put the cursor after them in Script Debugger and hit the
code-completion key: the number is shown in the list. But all you need to know
is (a) what they are, and (b) that you add them as if they are integers (give
or take a "get").
> 2) writeToFile:atomically: is an NSString instance method and seems to be
> deprecated.
Right. Without specifying encoding it's potentially meaningless.
> But when I try writeToFile:atomically:encoding:error: instead, I fumble:
>
> theData's writeToFile:"/path/to/file" atomically:true encoding:(current
> application's NSUTF8StringEncoding) |error|:NULL
>
> where SD seemingly complains about |error|...
AppleScript's equivalent of NULL is missing value.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>
_______________________________________________
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