convert xml to csv

asked 2020-07-26 13:25:56 -0500

Ghanshyam gravatar image

i am having a nested xml with repetitive tags, i wanted to convert it to csv. i have tried with field flattener but it doesn't help as it returns string of all fields which i can't able to convert to list using field order as there are too many columns. attached is the xml file. i have tried with a JS given in https://groups.google.com/a/streamset... thread but didn't able to convert it. sample xml:

<NS1:vehicleComponent xmlns:NS1="http://www.xyz.com/bhp/1/vehicleComponent"><NS1:effectiveDate>2020-07-02T23:13:45+00:00</NS1:effectiveDate><NS1:vehicleNumber>4O11417</NS1:vehicleNumber><NS1:rakeNumber>21N00034A</NS1:rakeNumber><NS1:trainNumber>21N00034-</NS1:trainNumber><NS1:positionInTrain>60</NS1:positionInTrain><NS1:componentCollection><NS1:component><NS1:typeOfComponent>Ore Car</NS1:typeOfComponent><NS1:componentCode>4O11417</NS1:componentCode><NS1:componentClass>G Class Ore Car</NS1:componentClass><NS1:totalTrips>0.0</NS1:totalTrips><NS1:tripsSinceLastService>0.0</NS1:tripsSinceLastService><NS1:totalDistance>0.0</NS1:totalDistance><NS1:distanceSinceLastService>0.0</NS1:distanceSinceLastService><NS1:buildTimestamp>2019-04-25T16:00:00+00:00</NS1:buildTimestamp><NS1:installTimestamp>2019-04-25T16:00:00+00:00</NS1:installTimestamp><NS1:lastUpdateTimestamp>2020-02-10T12:25:02+00:00</NS1:lastUpdateTimestamp><NS1:subcomponentCollection><NS1:component><NS1:typeOfComponent>Axle</NS1:typeOfComponent><NS1:positionCode>Wheelset 4</NS1:positionCode><NS1:componentCode>AXM19000696</NS1:componentCode><NS1:componentClass>H Class Axle</NS1:componentClass><NS1:totalTrips>186.97892271662872</NS1:totalTrips><NS1:tripsSinceLastService>186.97892271662872</NS1:tripsSinceLastService><NS1:totalDistance>159680.0</NS1:totalDistance><NS1:distanceSinceLastService>159680.0</NS1:distanceSinceLastService><NS1:buildTimestamp>2019-04-25T16:00:00+00:00</NS1:buildTimestamp><NS1:installTimestamp>2019-04-25T16:00:00+00:00</NS1:installTimestamp><NS1:lastUpdateTimestamp>2020-02-10T12:25:02+00:00</NS1:lastUpdateTimestamp><NS1:componentAttributeCollection><NS1:componentAttribute><NS1:attributeName>AX_CLASS</NS1:attributeName><NS1:attributeValue>HYBRID</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>AX_MANUFACT</NS1:attributeName><NS1:attributeValue>COMSTEEL</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>A end Axle Wh/seat End</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>A end Axle Wh/seat Front</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>A end Axle Wh/seat Middle</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>B end Axle Wh/seat End</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>B end Axle Wh/seat Front</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute><NS1:componentAttribute><NS1:attributeName>B end Axle Wh/seat Middle</NS1:attributeName><NS1:attributeValue>247.7</NS1:attributeValue></NS1:componentAttribute></NS1:componentAttributeCollection><NS1:subcomponentCollection><NS1:component><NS1:typeOfComponent>Wheel</NS1:typeOfComponent><NS1:positionCode>A End Wheel</NS1:positionCode><NS1:componentCode>WHM1800776573013</NS1:componentCode><NS1:componentClass>G Class Wheel</NS1:componentClass><NS1:totalTrips>186.97892271662872</NS1:totalTrips><NS1:tripsSinceLastService>186.97892271662872</NS1:tripsSinceLastService><NS1:totalDistance>159680.0</NS1:totalDistance><NS1:distanceSinceLastService>159680.0</NS1:distanceSinceLastService><NS1:buildTimestamp>2019-04-25T16:00:00+00:00</NS1:buildTimestamp><NS1:installTimestamp>2019-04-25T16:00:00+00:00</NS1:installTimestamp><NS1:lastUpdateTimestamp>2020-02-10T12:25:02 ...
(more)
edit retag flag offensive close merge delete