Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Dynamically incorporating an XML fragment

Avatar

Level 1

Dear everyone,

I am trying to bind some XML data to an existing node upon initialisation of the data node. I try the following:

var xml = ""
xml = xml + "<PEOPLE>"
xml = xml + "<DATA>"
xml = xml + "<NAME>Tim</NAME>"
xml = xml + "<JOB>Lumberjack</JOB>"
xml = xml + "</DATA>"
xml = xml + "<DATA>"
xml = xml + "<NAME>Jack</NAME>"
xml = xml + "<JOB>Programmer</JOB>"
xml = xml + "</DATA>"
xml = xml + "</PEOPLE>"
xfa.data.PEOPLE.loadXML(xml, true, true)

Since it does not seem to work, I display my data with the following comment on a text field:

xfa.datasets.saveXML("pretty")

This results in:

<?xml version="1.0" encoding="UTF-8"?>

<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
   <xfa:data>
      <data>
         <PEOPLE/>
      </data>
   </xfa:data>
   <dd:dataDescription xmlns:dd="http://ns.adobe.com/data-description/" dd:name="data">
      <data>
         <CRITERIA dd:dataNode="dataGroup"/>
      </data>
   </dd:dataDescription>
</xfa:datasets>

I would like to use this data later to bind a subform to the repeating data nodes and creating a dynamic list...


In short: my data does not get bound to begin with. I expect the issue to be with how I access the root node, there is nothing else I can think of.

Any input would be greatly appreciated!

Thanks a lot,

Tim

5 Replies

Avatar

Level 10

Hi Tim,

I've done this at the xfa.datasets level, have just tried at the xfa.data level and couldn't get it working.

Attached is my sample using xfa.datasets if that helps.

Bruce

Avatar

Level 1

Dear Bruce,

thank you very much for your answer.

Your example works perfectly!

When saving and reopening the form the dynamically created nodes are not there anymore, which isn't illogical per se, but I would like them to be there :-)

I want to dynamically create fields, have the user enter data in those and then save the form. The most convenient way would be to put it in an XML fragment and bind the subforms and elements to it. I tried creating and binding it in the data section, but was not really succesful. Do you have any ideas where to look?

Thanks a lot for your help.

Kind regards,

Tim

Message was edited by: Screenname_Tim

Avatar

Level 10

Hi Tim,

I just tried the sample I posted enabled with Acrobat and Reader Extensions and it worked in both cases, so aren't sure what the problem might be.

Do you mind posting your form?

Regards

Bruce

Avatar

Level 1

Hi Bruce,

thanks a lot for your help (and patience ;-)

I was probably not very clear, but I want to use the XML fragment to dynamically generate a form to be filled out, meaning that the data from the XML fragment will mainly have the labels for the text fields, while the text fields are later filled out by the user, saved and sent back (file attached).

Do you know whether it's possible to also store the XML data generated? That would create a lot of possibilities...

Thanks,

Tim

Avatar

Level 10

Hi Tim,

I think it is, I did play with dynamically generating a form a while back and this sample is as far as I got.

Click on "show $data" before adding the fields and then after and you can see the dynamically added fields have been included in the dataset.

The next step was to write a XSLT that took my form definition XML and generated the XFA, but that project never went ahead.

Bruce