Issue with Xml Reader

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 :


field21value
field22value


field22value
field23value


field212value


Mapping File 1 :
// DOES NOT WORK
<?xml version="1.0" encoding="UTF-8"?>







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"?>

Mapping File 3 :
// WORKS FINE

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

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)

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,