Expand my Community achievements bar.

how to create an attribute

Avatar

Former Community Member

Hi,

I can create xml elements in designer, e.g. John Brinkman's example

  // Add a question datagroup with the right question type

  // then add a question subform to bind against it.

                                                  var vNewQ = xfa.datasets.createNode("dataGroup", "Question");

                                                  vNewType = xfa.datasets.createNode("dataValue", "QuestionType");

                                                  vNewType.value = vQDef.QuestionType.value;

                                                  vNewQ.nodes.append(vNewType);

                                                  vSection.dataNode.nodes.append(vNewQ);

However, I would like to create an attribute (I'm working with an existing predefined schema) but I can't seem to find a simple way, e.g.

I would like something like

<Question QuestionType=""/>

How can I do this? I tried loading the XML in like

                                                  var vNewType          =

                                                                                                      <Question QuestionType="">

                                                                                                      </Question>;

 

 

                                                  xfa.data.mForm.loadXML(vNewType.toString(), false, false);

but unless I give it a child node, it bombs out. It will work with

  var vNewType =

    <Question QuestionType="">

       <dummyRow/>

    </Question>;

Any help would be worth 5 gold medals.


2 Replies

Avatar

Level 10

Hi,

You need to set the contains property of the dataValue to 'metaData" to turn it into an attribute, but you can only do this once the dataValue has a parent, so your code should look like;

var vNewQ = xfa.datasets.createNode("dataGroup", "Question");

vNewType = xfa.datasets.createNode("dataValue", "QuestionType");

vNewType.value = vQDef.QuestionType.value;

vNewQ.nodes.append(vNewType);

vNewType.contains = "metaData";

vSection.dataNode.nodes.append(vNewQ);

Regards

Bruce

Avatar

Former Community Member

gold medal winner. I would have never guessed. thank you