Hi,
I can't seam to figure out how to create an attribute in a data node dataGroup.
For instance, take the following data structure:
<Root>
<Description id="123">
<item>Item 1</item>
<item>Item 2</item>
</Description>
</Root>
Using javascript, I want to create an attribute in Description element:
<Root>
<Description id="123" key="321">
<item>Item 1</item>
<item>Item 2</item>
</Description>
</Root>
NOT:
<Root>
<Description id="123">
<item>Item 1</item>
<item>Item 2</item>
<key>123</key>
</Description>
</Root>
That I would get with the createNode method.
Any ideas?
Thanks.
Kyle
Views
Replies
Total Likes
OK let me preface this with--I could easily be wrong about this: So take the following with a grain of salt:
In XFA, an attribute is actually a sibling of the child elements in the SOM hiearchy--your experience seems to bear that out. I tried manually adding a custom attribute to the XML in Designer and then tried to subsequently change its value. Even though the custom attribute existed, I could not change it through scripting--Acrobat said there was no such attribute, even though it was plainly there.
I believe the only way to create a custom "attribute like" property to an object on an XFA form is by using the "extras" element--you can assign a name and/or id properties or use its integer child or text child. And, this is probably of no help.
I'm interested to see if you discover a better way.
Views
Replies
Total Likes
Hi Stephen,
I think Kyle is asking about adding an attribute to a node in the data connection. If that is right then the contains property of the dataValue node needs to be set to "metaData". So something like;
var keyNode = xfa.datasets.createNode("dataValue", "key");
keyNode.value = "321";
$data.Root.Description.nodes.append(keyNode);
keyNode.contains = "metaData"
There are a couple of tricks though
1. The value of a dataValue must always be a string ("321" not 321).
2. The contains property can only be set once the dataValue's parent has been set.
Sorry if I've misunderstood Kyle's problem, but I think the problem you are having might be because "strict scoping" is turned on and the custom attribute has been garbage collected, I think you are right that the "extras" (or the "desc") element is a better approach for form nodes.
Regards
Bruce
Views
Replies
Total Likes
Thank you both for your prompt and concise replies.
Unfortunately I didn't have the chance to test out your solutions since the problem kindof solved itself.
Once I binded the form to a new schema (with the attribute added) any SOM expression refrencing that node name assumed it was an attribute based on the data description created in the template.
Kyle
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies