There is some terminal command for parsing xml to csv in python xq syntax (also python-yq installed required):
xq -r '[.yml_catalog.shop.offers.offer[] | [."@id", ."@available", .price, .name, .description]] | . |= [["id", "available", "price", "name", "description"]] + . | .[] | @csv' source.yml > result.csv
Here is xml file example:
<?xml version="1.0" encoding="UTF-8"?>
<yml_catalog date="2020-07-29 09:39">
<shop>
<offers>
<offer id="17489" available="true">
<price>1500</price>
<name>Item 1</name>
<description>Item 1 description</description>
<param name="category type">sale</param>
<param name="size">big</param>
</offer>
<offer id="17490" available="false">
<price>1100</price>
<name>Item 2</name>
<description>Item 2 description</description>
<param name="category type">main</param>
<param name="size">small</param>
</offer>
...
</offers>
</shop>
</yml_catalog>
I need to add param tags for parsing. I've tried to handle its by ."param[@name="category type"]", ."param[@name=category type] (the same for the param tag with size attribute), but it doesn't work.
Necessary output csv:
"id","available","price","name","description","category","size"
"17489","true","1500","Item 1","Item 1 description","sale","big"
"17490","false","1100","Item 2","Item 2 description","main","small"
Please give me advice how to handle tags with exact properties with values and get its text text contents?
Thank you!