Re: XML attributes
Re: XML attributes
- Subject: Re: XML attributes
- From: Jörgen Stahle <email@hidden>
- Date: Tue, 27 Nov 2018 09:03:30 +0100
Your last answer solved the specified issue, Shane.
But then I ran into another one...
I CAN create this XML
<example>
<format date="20181126" product="NYH">
<pages subProduct="105">
<page id="243" template="template1.indd"></page>
</pages>
</format>
</example>
Input record:
*set* theRecord *to* {format:{attributes:{|date|:"20181126", product
:"NYH"}, pages:{attributes:{subProduct:"105"}, page:{attributes:{|id|
:"243", template:"template1.indd"}}}}}
But i CAN NOT create this one with multiple "page" sub elements
<example>
<format date="20181126" product="NYH">
<pages subProduct="105">
<page id="243" template="template1.indd"></page>
<page id="244" template="template2.indd"></page>
</pages>
</format>
</example>
Input record (one of then I tried):
*set* theRecord *to* {format:{attributes:{|date|:"20181126", product
:"NYH"}, pages:{{attributes:{subProduct:"105"}, page:{{attributes:{|id|
:"243", template:"template1.indd"}}, {attributes:{|id|:"242", template
:"template2.indd"}}}}}}}}
I have used hours to try several variants for input (using the key
value_and_attributes and so on). Here the value of "page" is just a list
representing the subelements. That looks wrong, logically, but of course AS
can't use the same name twice in a record. And when going the other way,
from XML to record using your code Shane, a list of several subelements is
represented in the same way – with the name of the subelements being used
as the name of the list.
Confusing to work with, but I'm trying hard :-)
Den mån 26 nov. 2018 kl 15:51 skrev Jörgen Stahle <email@hidden>:
> Well, your answer solved the specified issue, Shane. But then I ran into
> another issue...
>
> I CAN create this XML
>
> <example>
> <format date="20181126" product="NYH">
> <pages subProduct="105">
> <page id="243" template="template1.indd"></page>
> </pages>
> </format>
> </example>
> Input record:
>
> *set* theRecord *to* {format:{attributes:{|date|:"20181126", product:"NYH"},
> pages:{attributes:{subProduct:"105"}, page:{attributes:{|id|:"243",
> template:"template1.indd"}}}}}
>
> But i CAN NOT create this one with multiple "page" sub elements
> <example>
> <format date="20181126" product="NYH">
> <pages subProduct="105">
> <page id="243" template="template1.indd"></page>
> <page id="244" template="template2.indd"></page>
> </pages>
> </format>
> </example>
>
> Input record (one of then I tried):
>
> *set* theRecord *to* {format:{attributes:{|date|:"20181126", product:"NYH"},
> pages:{{attributes:{subProduct:"105"}, page:{{attributes:{|id|:"243",
> template:"template1.indd"}}, {attributes:{|id|:"242", template
> :"template2.indd"}}}}}}}}
>
> I have used hours to try several variants for input (using the key
> value_and_attributes and so on). Here the value of "page" is just a list
> representing the subelements. That looks wrong, logically, but of course AS
> can't use the same name twice in a record. And when going the other way,
> from XML to record using your code Shane, a list of several subelements is
> represented in the same way – with the name of the subelements being used
> as the name of the list.
> Confusing to work with, but I'm trying hard :-)
>
>
>
>
>
> Den mån 26 nov. 2018 kl 08:30 skrev Jörgen Stahle <email@hidden>:
>
>> That solved it. Thanks a lot Shane, again!
>>
>> Den sön 25 nov. 2018 kl 02:16 skrev Shane Stanley <
>> email@hidden>:
>>
>>> On 24 Nov 2018, at 11:07 pm, Shane Stanley <email@hidden>
>>> wrote:
>>>
>>>
>>> Would something like this work for you:
>>>
>>>
>>> Let me clean up some of the nomenclature there:
>>>
>>> *on* addChildOrAttributesTo: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)
>>> *if* theKey *as* *text* = "attributes" *then*
>>> (parentElement's setAttributesWithDictionary:theValue)
>>> *else* *if* theKey *as* *text* = "value_and_attributes" *then*
>>> *set* newDict *to* (theDict's objectForKey:theKey)
>>> *set* newName *to* (newDict's objectForKey:"value")
>>> *set* theAtts *to* (newDict's objectForKey:"attributes")
>>> (parentElement's setAttributesWithDictionary:theAtts)
>>> (parentElement's setObjectValue:newName)
>>> *else*
>>> *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* addChildOrAttributesTo:newElement withDictionary:theValue)
>>> *else*
>>> (newElement's setObjectValue:theValue)
>>> *end* *if*
>>> *end* *if*
>>> *end* *repeat*
>>> *end* addChildOrAttributesTo:withDictionary:
>>>
>>>
>>> --
>>> 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
>>>
>>
_______________________________________________
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