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
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
-
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: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. -
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. -
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,
Please sign in to leave a comment.
Comments 3