Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 1

XML to CSV Dilemma

Hi! I'm new to github, so I apologize in advance if my formatting isn't correct.

 

I have a program that provides an output file in a given xml format shown here:

 

<?xml version="1.0" ?>
<events ssi-v="2">
    <event sender="audio" event="emotion" from="2487" dur="250" prob="1.000000" type="MAP" state="COMPLETED" glue="0">
        <tuple string="anger" value="0.000001" />
        <tuple string="boredom" value="0.100000" />
        <tuple string="disgust" value="0.008459" />
        <tuple string="fear" value="0.004076" />
        <tuple string="happiness" value="0.000000" />
        <tuple string="neutral" value="0.000000" />
        <tuple string="sadness" value="0.100000" />
    </event>
    <event sender="audio" event="emotion" from="2735" dur="250" prob="1.000000" type="MAP" state="COMPLETED" glue="0">
        <tuple string="anger" value="0.000000" />
        <tuple string="boredom" value="0.200000" />
        <tuple string="disgust" value="0.000000" />
        <tuple string="fear" value="0.000000" />
        <tuple string="happiness" value="0.000000" />
        <tuple string="neutral" value="0.000000" />
        <tuple string="sadness" value="0.200000" />
    </event>
    <event sender="audio" event="emotion" from="2986" dur="250" prob="1.000000" type="MAP" state="COMPLETED" glue="0">
        <tuple string="anger" value="0.000000" />
        <tuple string="boredom" value="0.300000" />
        <tuple string="disgust" value="0.008207" />
        <tuple string="fear" value="0.000189" />
        <tuple string="happiness" value="0.000000" />
        <tuple string="neutral" value="0.000000" />
        <tuple string="sadness" value="0.300000" />
    </event>
</events>

 

 

 The problem arises with the rest of my workflow.  When I convert the file into .csv, the format isn't viable for me to work with. 

 

Ideally, I want xml that looks likes this:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <row>
    <Event>1</Event>
    <Anger>0.3334527</Anger>
    <Boredom>0.002746525</Boredom>
    <Disgust>0.059587375</Disgust>
    <Fear>0.01567785</Fear>
    <Happiness>0.00039325</Happiness>
    <Neutral>0.106268225</Neutral>
    <Sadness>0.053649925</Sadness>
  </row>
  <row>
    <Event>2</Event>
    <Anger>0.116595575</Anger>
    <Boredom>0.00066055</Boredom>
    <Disgust>0.074866825</Disgust>
    <Fear>0.007258975</Fear>
    <Happiness>0.00482305</Happiness>
    <Neutral>0.325449475</Neutral>
    <Sadness>0.0479154</Sadness>
  </row>
  <row>
    <Event>5</Event>
    <Anger>0.0995256</Anger>
    <Boredom>0.00166825</Boredom>
    <Disgust>0.06238415</Disgust>
    <Fear>0.246183425</Fear>
    <Happiness>0.026338775</Happiness>
    <Neutral>0.010681325</Neutral>
    <Sadness>0.1052269</Sadness>
  </row>
  <row>
</root>

 

 

Do you have any suggestions on how I can automate this?

To make it easier to visualize, I have attatched a pdf file that shows the xml files and the corresponding csv's they create.

Here it is