Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling XML ARRAY Objects #28

Closed
lightonphiri opened this issue Mar 26, 2022 · 2 comments
Closed

Handling XML ARRAY Objects #28

lightonphiri opened this issue Mar 26, 2022 · 2 comments

Comments

@lightonphiri
Copy link

I am converting XML encoded data to CSV, however, some nested elements appear as "ARRAY" objects: see sample command and output below.

data$ catmandu convert OAI --metadataPrefix qdc --url http://dspace.unza.zm/oai/request to CSV | cat -n | more      
1  _about,_datestamp,_id,_identifier,_metadata,_resumption,_resumptionToken,_setSpec,_status
2  ARRAY(0x2141480),2019-08-19T12:30:47Z,oai:dspace.unza.zm:123456789/4153,oai:dspace.unza.zm:1234567
89/4153,ARRAY(0x42a0010),HASH(0x3bdf138),qdc////100,ARRAY(0x3c47d40),

I would like to create a CSV file with all headers and values for each of the ARRAY objects, however, I am having challenges using join_fields.

On a related note, how would one print out the entire ARRAY contents?

@jorol
Copy link
Member

jorol commented Mar 26, 2022

Hi,

you can use the "collapse" fix to flatten the nested data structure:

$ catmandu convert OAI --metadataPrefix qdc --url http://dspace.unza.zm/oai/request to CSV --fix 'collapse()'

... or use the "oai_dc" handler option with the "join_field" fix on array fields:

$ catmandu convert OAI --metadataPrefix qdc --url http://dspace.unza.zm/oai/request --handler oai_dc to CSV --fields abstract --fix 'join_field(abstract,";")'

Cheers

@lightonphiri
Copy link
Author

Thank you for this. I did try out collapse after seeing an issue on here: no luck there.

I ended up exporting to JSON and working with JSON. It turns out, I am processing the data via Pandas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants