Parse XML using shell/python and store both attributes and data between tags in CSV

I am currently working on a project in which data is structured in an XML . The problem I am having is that some tags may appear or may not appear and, besides the fact that I need to store the data between the element tags, I also have to store the data in the attributes. I need to store this values in a csv file. I am new to XML and also python/shell so this is quite difficult for me. Can you provide some assistance? Here is an example of a file.

    <PrimaryOfferList creationDate="2015-04-30" sequenceNumber="102" elementCount="1">
            <name>Mobile Internet</name>
                <!-- May contain one  or more values -->
                <!-- May contain one  or more values -->
            <!-- May contain one  or more values -->
            <supplementOffer occurrence="Optional">
            <supplementOffer occurrence="Mandatory">
            <supplementOffer occurrence="Conditional">
            <supplementOffer occurrence="Optional">
            <offerGroup occurence="Optional">
            <offerGroup occurence="Mandatory">
            <!-- The number of supplement offers and offergroups vary depending on the file - so I need to read them dinamically -->

Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.