Issue with Xml Reader

Discussion on developing CloverETL engine, transformation components etc.

madan_clover3
Posts: 16
Joined: Tue Jun 10, 2014 10:39 am

Issue with Xml Reader

Postby madan_clover3 » Wed May 04, 2016 7:25 am

Hi,

Trying to read xml data with XmlReader. Below are data and mapping files,

Mapping file 2 and 3 working fine. Mapping file 1 is giving exception (added below). Please clarify me is it expected behavior or issue with component.

Data File :
<Dataset>
<Entity2 attribute21="attribute21value">
<field21>field21value</field21>
<field22>field22value</field22>
</Entity2>
<Entity2>
<field22>field22value</field22>
<field23>field23value</field23>
<Entity21 attribute211="attribute211value">
<field211/>
<field212>field212value</field212>
</Entity21>
</Entity2>
</Dataset>


Mapping File 1 :
// DOES NOT WORK
<?xml version="1.0" encoding="UTF-8"?>
<Context xpath="Dataset">
<Context xpath="Entity2">
<Context outPort="0" xpath="Entity21">
<Mapping cloverField="targetfield2" xpath="field211"/>
<Mapping cloverField="targetfield1" xpath="@attribute211"/>
</Context>
</Context>
</Context>

ERROR MESSAGE :
Exception occured while transforming data.Component [XML_Reader] finished with status ERROR. (Out0: 1 recs, Out1: 0 recs)
XPath 'Entity2' contains two or more values!



Mapping File 2 :
// WORKS FINE
<?xml version="1.0" encoding="UTF-8"?>
<Context xpath="Dataset">
<Context outPort="0" xpath="Entity2/Entity21">
<Mapping cloverField="targetfield2" xpath="field211"/>
<Mapping cloverField="targetfield1" xpath="@attribute211"/>
</Context>
</Context>

Mapping File 3 :
// WORKS FINE
<?xml version="1.0" encoding="UTF-8"?>
<Context xpath="Dataset">
<Context outPort="0" xpath="Entity2">
<Mapping cloverField="targetfield" xpath="field21"/>
<Context outPort="1" xpath="Entity21">
<Mapping cloverField="targetfield2" xpath="field211"/>
<Mapping cloverField="targetfield1" xpath="@attribute211"/>
</Context>
</Context>
</Context>


Thank you,
Madan

vazquezrosariop
Posts: 107
Joined: Mon Feb 29, 2016 5:33 pm

Re: Issue with Xml Reader

Postby vazquezrosariop » Thu May 05, 2016 4:25 pm

Hi,

That is the expected behavior for the XMLReader the reason being is since Entity2 is ambiguous CloverETL can’t determine which element to choose from. When you define a Context tag the element shouldn’t be ambiguous, you should specify to the exact element you want to read from. In this case the second mapping approach is the best option, but I would recommend that you use a single xpath expression:

Code: Select all

xpath=”/Dataset/Entity2/Entity21”


I would also recommend that you use the XMLExtract component, the reason being it’s easier to use and safer in terms of out of memory issues.
---
Pedro Vazquez Rosario
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com
How to speed up communication with CloverCARE support

madan_clover3
Posts: 16
Joined: Tue Jun 10, 2014 10:39 am

Re: Issue with Xml Reader

Postby madan_clover3 » Tue May 10, 2016 9:16 am

Thanks for explanation. I have tried Xml Extract as well. Problem with Xml Extract(SAX way) is we cannot map one source element to multiple target elements. In such case only last mapped element is getting data. (only fld3, fld4 is getting data in below case)

<Mappings>
<Mapping element="Dataset">
<Mapping element="Entity2">
<Mapping cloverFields="fld1;fld2;" element="Entity21" outPort="1" xmlFields="{}attribute211;{}field211;"/>
<Mapping cloverFields="fld3;fld4;" element="Entity21" outPort="2" xmlFields="{}attribute211;{}field211;"/>
</Mapping>
</Mapping>
</Mappings>

Any better approach with above case, suggestions please.

Thank you.

vazquezrosariop
Posts: 107
Joined: Mon Feb 29, 2016 5:33 pm

Re: Issue with Xml Reader

Postby vazquezrosariop » Fri May 13, 2016 4:37 pm

Hi,

Unfortunately, you can’t map the same element to two different output ports. I would recommend that you extract the field first and then use SimpleCopy or Reformat to map the source elements to multiple target elements.

Best Regards,
---
Pedro Vazquez Rosario
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com
How to speed up communication with CloverCARE support


cron