title: XML CSV convert with Python
body: <p>I want to make a command line program that will hopefully work on both Windows and Linux.  I want to use Python since it is my programming language of choice.  The goal is the make the program take file name as an argument, and output the information from the file in a different format.  In this case XML -> CSV and CSV -> XML.  </p>
  
  <p>What is the best way to do this?</p>
  
  <p>I know there are XML and CSV parsers in Python, like <code>xml.parsers.expat</code> and <code>csv</code> libraries. I want the program to be robust, so that perhaps it could output in other formats, like .sql or something.  Would be beneficiary to convert the data into a standard format first?  Like JSON?  Then the output file could be made into other formats in necessary.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT::</p>
  
  <pre><code>&lt;level1 id ='' attr1='' attr2=''&gt;
      &lt;level2 id ='' attr1='' attr2=''&gt;
          &lt;type1 id ='' attr1='' attr2=''&gt;
          &lt;/type1&gt;
          &lt;type2 id ='' attr1='' attr2=''&gt;
          &lt;/type2&gt;
      &lt;/level2&gt;
      &lt;level2 id ='' attr1='' attr2=''&gt;
          &lt;type2 id ='' attr1='' attr2=''&gt;
          &lt;/type2&gt;
      &lt;/level2&gt;
  &lt;/level1&gt;
  </code></pre>
  
  <p>This is the XML format.  Notice the type1 and type2 inside the level2.  Now how should I represent this line by line in a csv?</p>
  
  <p>EDIT #2:</p>
  
  <p>I guess this question comes down to standard way to convert between a tree-like data structure and a grid structure.  I ended up making a nested list in python, like JSON but didn't used the JSON structure.  I wonder if there is a good algorithm in general for making this conversion?</p>