XMLExtract - copying parent fields to child when parent fields are present after child element

Hi,

I am using XMLExtract for reading xml files. I have a doubt regarding parentKey&generatedKey feature to copy parent data to child.

Consider below data and extraction mapping :

Data :


<department>
  <employee>
      <id>E001</id>
      <name>emp1</name>
      <deptRef></detpRef>
  </employee>
  <id>D001</id>
  <name>Dept1</name>
</department>

Extraction Mapping :


<Mappings>
  <Mapping element="department" outPort="0" xmlFields="{}id;{}name" cloverFields="deptId;name">
    <Mapping element="employee" outPort="1" xmlFields="{}id;{}name" cloverFields="id;name" parentKey="deptId" generatedKey="detpRef">
    </Mapping>
  </Mapping>
</Mappings>

In the above scenario, I am trying to copy department id field data to employee field which is ‘deptRef’. But department ‘id’ comes after ‘employee’ in the data file. As data is read using XMLExtract (SaxParser), will the above case works fine ? Will ‘deptRef’(of employee) gets the value of ‘id’(of department) ?

Hello,
as you rightly indicated, using the XMLExtract in this use case is not an ideal solution due to the way SAX parsing of XML files works. I have attached an example graph and 2 input files to demonstrate the following:

  • phase 0 - using XMLExtract to push the ‘D001’ value into the ‘deptRef’ child field is not viable

  • phase 1 - using the same mapping of XMLExtract but with a slightly different input file (input2.xml), you can see that because the department id comes earlier than the child elements, it is possible to map the parent field to the child easily

  • phase 2 - using XMLReader to push the ‘D001’ value into the ‘deptRef’ child field is perfectly viable

Kind regards,