LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

XML to CSV conversion #362

Closed eirtech closed 5 years ago

eirtech commented 5 years ago

Hi, In conversion from XML to CSV, it is converted to a one field which is an ARRAY. Actually, as most of the XML file, it has a node which represents a single record. But it sees this as an ARRAY and just shows a CSV, contains one column with the node name including one record as an ARRAY. Would you please help me how to solve this issue? Thanks in advanced.

nics commented 5 years ago

Hi, can you give us an example of the XML structure?

jorol commented 5 years ago

You can address the record nodes via XPath and flatten the nested data structure

$ catmandu convert XML --path '//record_node' to CSV --fix 'collapse()' < records.xml

or join the array elements:

$ catmandu convert XML --path '//record_node' to CSV --fix 'join_field(.,",")' < records.xml
eirtech commented 5 years ago

Thanks @jorol. It worked well.