title: Convert xml to pdf in Python
body: <p>I have a problem when I try to convert a XML file in a PDF file, here I’m going to explain briefly how I try to generate a PDF file.</p>
  
  <p>We suppose I get the information from a database, then the code source is the following:</p>
  
  <pre><code>import pyodbc,time,os,shutil,types
  import cStringIO
  import ho.pisa as pisa
  import urllib
  
  def HTML2PDF(data, filename, open=False):
  
      """
      Simple test showing how to create a PDF file from
      PML Source String. Also shows errors and tries to start
      the resulting PDF
      """
  
      pdf = pisa.CreatePDF(
          cStringIO.StringIO(data),
          file(filename, "wb"))
  
      if open and (not pdf.err):
          os.startfile(str(filename))
  
      return not pdf.err
  
  
  fout = open(BE_Full.xml","w")
  fout.write("&lt;?xml-stylesheet type='text/xsl' href='styles/Full_Report.xslt' alternate='no' title='Short' ?&gt;")
  fout.write("&lt;files&gt;")
  fout.write("&lt;validationreport&gt;") 
  fout.write("xmlvalidations/" + row.country + "_validation_" + row.dbversion + ".xml")
  fout.write("&lt;/validationreport&gt;")
  fout.write("&lt;reportformat&gt;reports/EN_Report.xml&lt;/reportformat&gt;")
  fout.write("&lt;/files&gt;")
  fout.write
  fout.close()
  f =   urllib.urlopen("file:///C:/Documents%20and%20Settings/dmarban/Escritorio/python/BE_Full.xml")
  s = f.read()
  f.close()
  
  HTML2PDF(s, "test.pdf", open=True)
  </code></pre>
  
  <p>The first I generate is an XML file that has the following content:</p>
  
  <pre><code>&lt;?xml-stylesheet type='text/xsl' href='styles/Full_Report.xslt' alternate='no' title='Short' ?&gt;
  &lt;files&gt;
   &lt;validationreport&gt;xmlvalidations/BE_validation_mid2010.xml&lt;/validationreport&gt;
   &lt;reportformat&gt;reports/EN_Report.xml&lt;/reportformat&gt;
  &lt;/files&gt;
  </code></pre>
  
  <p>When I execute this code:</p>
  
  <pre><code>urllib.urlopen("file:///C:/Documents%20and%20Settings/dmarban/Escritorio/python/BE_Full.xml")
      s = f.read()
      f.close()
  HTML2PDF(s, " BE_Full.pdf ", open=True)
  </code></pre>
  
  <p>It generates me the next file “BE_Full.pdf”, but instead of showing the contents of the folder “xmlvalidations/BE_validation_mid2010.xml” show me the contents of the labels that they are in pdf, It would show the following code:</p>
  
  <pre><code>xmlvalidations/BE_validation_mid2010.xml reports/EN_Report.xml
  </code></pre>
  
  <p>My question is, How I can parser a XML file in python, I read it as an HTML file?</p>