Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to create an attribute in a data node

Avatar

Former Community Member

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

3 Replies

Avatar

Level 7

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.

Avatar

Level 10

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

Avatar

Former Community Member

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