In this article I demonstrates some tips and techniques that can be followed while trying to map PDF XFA data to a XFA template.
As you may know, XFA datasets and XFA templates play major roles in rendering components in a viewer. You can find more information about how to access a XFA dataset or XFA template using JPedal library on our support website.
If a data map has the same number of template form elements then using XML dataset will be helpful, however if there is a mismatch (especially in quantity in dynamic forms) then we have to rename the xml data elements or template elements to match correctly.
Let us consider this example dataset and template
Dataset:
<Team>
<Employee>
<Name>John</Name>
<Address>25 abc road, AB1234</Address>
</Employee>
</Team>
Template:
<subform name=’Team’>
<subform name=’Employee’>
<field name=’Name’></field>
<field name=’Address’></field>
subform>
subform>
above the xml code defines static subform and simple data set; so we can match the data as it is defined in template.
Example 1 : [add another static field]
let us add another address to the template with the same field name.
<subform name=’Team’>
<subform name=’Employee’>
<field name=’Name’></field>
<field name=’Address’></field>
<field name=’Address’></field>
subform>
</subform>
at this point we have to rename similar name fields to map the data correctly. so rename displays as below with any different attribute
<field name=’Address’ yourAtrName=’Address[0]’></field>
<field name=’Address’ yourAtrName=’Address[1]’></field>
Note: (if you like you can rename the whole xml dataset and tempate to [] array format to match correctly)
Example 2 : [handle dynamic forms]
The occurrence limits control how many times they are copied into the Form DOM during a merge operation; any subforms becomes dynamic if max attribute of occur element is not 1. So in above example let us make the maximum employees to unlimited occurrence using -1.
<subform name=’Employee’>
<occur max=”-1″/>
and we insert one more employee detail to the dataset and we insert naming attribute as array to differentiate employee1 from employee2
<Team>
<Employee yourAtrName=’Employee[0]’>
<Name>John</Name>
<Address>25 abc road, AB1234</Address>
</Employee>
<Employee yourAtrName=’Employee[1]’>
<Name>david</Name>
<Address>32 xyz road, XY1234</Address>
</Employee>
</Team>
while rendering template we could either clone the dynamic node as per data set occurrence and rename as array or we could process it in memory during data binding process.
Example 3: handling transparent forms
There is a possibility that a template can consist of subform which has no attribute “name”. During the process we have to ignore the data binding or attribute naming for such elements.
<subform h=’11pt’ w=’33pt’> //subform has no name attribute so it is transparent
Example 4: do not populate the data to fields or subforms those data bind match is none
finally we have to ignore elements in data binding process that contain no data bind match values
i.e. <subform> <bind match=”none”/> </subform>
I hope that you will find this information useful; if you are attempting to match the XFA data to template.