title: python xml to string, insert into postgres
body: <p>Here is my code:</p>
  
  <pre><code>#!/usr/bin/python
  
  import psycopg2
  import sys
  from lxml import etree
  def main():
  
      #Define our connection string
      conn_string = ("host=host dbname=lal user=user password=pass")
  
  
      # get a connection, if a connect cannot be made an exception will be raised here
      conn = psycopg2.connect(conn_string)
  
      # conn.cursor will return a cursor object
      cursor = conn.cursor()
      print "Connected!\n"
  
      # Open file
  
  
      parser = etree.parse("XML/epg.xml")
      for row in parser:
          print row
  
          postgres = ('INSERT INTO epg_live (channel_id, program, start, duration) VALUES (%s, %s, %s, %s)', (row, row, row, row))
          cursor.execute(parser,postgres)
          cursor.commit()
          print "Gotovo!"
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Can you help me with parsing XML file to string and insert into table in posgresql.
  When I run script i get errors like:</p>
  
  <pre><code>File "./xml.py", line 32, in &lt;module&gt;
      main()
    File "./xml.py", line 22, in main
      parser = etree.parse("XML/epg.xml")
    File "lxml.etree.pyx", line 2953, in lxml.etree.parse (src/lxml/lxml.etree.c:56204)
    File "parser.pxi", line 1533, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:82287)
    File "parser.pxi", line 1562, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:82580)
    File "parser.pxi", line 1462, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:81619)
    File "parser.pxi", line 1002, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:78528)
    File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74472)
    File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75363)
    File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74696)
  lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: epg line 2 and item, line 26, column 10
  </code></pre>
  
  <p>My XML is fine it looks like:</p>
  
  <pre><code>&lt;item&gt;&lt;program&gt;        Program 3   
  &lt;/program&gt;&lt;start&gt;            Start   20130918 15:00:00 
  &lt;/start&gt;&lt;duration&gt;            Duration   04:30:00 
  &lt;/duration&gt;&lt;title&gt;                  Title Nujna seja Odbora za finance in monetarno politiko   
  &lt;/title&gt;&lt;/item&gt;
  </code></pre>
  
  <p>Can you help me with some solution for python, thx guys for reading this post.</p>