diff --git a/lib/json_support_functions.py b/lib/json_support_functions.py
deleted file mode 100644
index 01a2ee21cd35a09da19b6db8739e249c30bed449..0000000000000000000000000000000000000000
--- a/lib/json_support_functions.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre
-# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
-#
-# This file is part of participatorio/opendata
-#
-# participatorio/opendata is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-# USA.
-
-import MySQLdb
-import codecs
-import datetime
-import base64
-
-import string_functions as strf
-import queries_definition as qry
-
-######################################################################
-# Support functions:
-
-#--------------------------------------------------------------------#
-def open_json_file (json_filename):
-    json_file = codecs.open(json_filename,'w',encoding='utf-8')
-    return json_file
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_open_tag (xml, l, tag_name, sep):
-    if len(tag_name) > 0:
-        xml.write(strf.lvl(l)+"\""+tag_name+"\""+":"+sep+"\n")
-    else:
-        xml.write(strf.lvl(l)+sep+"\n")
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_close_tag (xml, l, sep, comma_flag):
-    if comma_flag == True:
-        xml.write(strf.lvl(l)+sep+","+"\n")
-    else:
-        xml.write(strf.lvl(l)+sep+"\n")    
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_tag (xml, l, tag_name, info_str, comma):
-    name="\""+tag_name+"\""
-    info="\""+strf.substbadc(info_str)+"\""
-    xml.write(strf.lvl(l)+name+":"+info+comma+"\n")
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_comments (db, xml, post_guid):
-    post_comments = db.cursor()
-    post_comments.execute(qry.qry_post_comments, (post_guid,))
-    
-    write_open_tag(xml,4,"comentarios","[")
-    
-    row=0
-    for (user_id, user_name, user_username, string, time)\
-        in post_comments:
-        
-        row=row+1
-        
-        write_open_tag(xml,5,"","{")
-        
-        prefix='profile/'
-        user_attr=strf.urlparticipa(prefix,user_username)
-                
-        write_open_tag(xml,6,"usuario","{")
-        write_tag(xml,7,"uid",user_attr,",")
-        write_tag(xml,7,"nome",user_name,"")
-        write_close_tag(xml,6,"}",True)
-        
-        write_tag(xml,6,"data",strf.datestr(time),",")
-        write_tag(xml,6,"mensagem",string,"")
-        
-        write_close_tag(xml,5,"}",(row < post_comments.rowcount))
-        
-    write_close_tag(xml,4,"]",False)
-    
-    post_comments.close()
-#--------------------------------------------------------------------#
-
-######################################################################
diff --git a/lib/opendata_json_class.py b/lib/opendata_json_class.py
new file mode 100644
index 0000000000000000000000000000000000000000..94532c97496f569f14ff32b4cc40a525f3b54fa7
--- /dev/null
+++ b/lib/opendata_json_class.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre
+# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+#
+# This file is part of participatorio/opendata
+#
+# participatorio/opendata is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+import MySQLdb
+import codecs
+import datetime
+import base64
+
+import opendata_string_functions as strf
+import opendata_queries_definition as qry
+
+class OpendataJSON:
+
+    database = None
+    indentation = None
+    level = None
+    dir_results = None
+    filename = None
+    out_file = None
+    
+    #--------------------------------------------------------------------#    
+    def __init__ (self, database, dir_results, filename):
+        self.database = database
+        
+        self.indentation = 0
+        self.level = strf.lvl(self.indentation)
+        
+        self.dir_results = dir_results
+        self.filename = filename
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def update_indentation(self, increment):
+        self.indentation=self.indentation+(increment)
+        self.level = strf.lvl(self.indentation)
+    #--------------------------------------------------------------------#
+        
+    #--------------------------------------------------------------------#
+    def open_file (self):
+        self.out_file=codecs.open(self.out_filename,'w',encoding='utf-8')
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def close_file (self):
+        self.out_file.close()
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_open_tag (self, tag_name, sep):
+        if len(tag_name) > 0:
+            self.out_file.write(self.level+"\""+tag_name+"\""+":"+sep+"\n")
+        else:
+            self.out_file.write(self.level+sep+"\n")
+        self.update_indentation(+1)
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_close_tag (self, sep, comma_flag):
+        self.update_indentation(-1)
+        if comma_flag == True:
+            self.out_file.write(self.level+sep+","+"\n")
+        else:
+            print(self.level+sep+"\n")
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_tag (self, tag_name, info_str, comma):
+        name="\""+tag_name+"\""
+        info="\""+strf.substbadc(info_str)+"\""
+        print(self.level+name+":"+info+comma+"\n")
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_comments (self, post_guid):
+        post_comments = self.database.cursor()
+        post_comments.execute(qry.qry_post_comments, (post_guid,))
+        
+        self.write_open_tag("comentarios","[")
+        
+        row=0
+        for (user_id, user_name, user_username, string, time)\
+            in post_comments:
+            
+            row=row+1
+            
+            self.write_open_tag("","{")
+            
+            prefix='profile/'
+            user_attr=strf.urlparticipa(prefix,user_username)
+                    
+            self.write_open_tag("usuario","{")
+            self.write_tag("uid",user_attr,",")
+            self.write_tag("nome",user_name,"")
+            self.write_close_tag("}",True)
+            
+            self.write_tag("data",strf.datestr(time),",")
+            self.write_tag("mensagem",string,"")
+            
+            self.write_close_tag("}",(row < post_comments.rowcount))
+            
+        self.write_close_tag("]",False)
+        
+        post_comments.close()
+    #--------------------------------------------------------------------#
diff --git a/lib/queries_definition.py b/lib/opendata_queries_definition.py
similarity index 100%
rename from lib/queries_definition.py
rename to lib/opendata_queries_definition.py
diff --git a/lib/string_functions.py b/lib/opendata_string_functions.py
similarity index 99%
rename from lib/string_functions.py
rename to lib/opendata_string_functions.py
index 0c4e292ad249caafa844778f9667535aa3d66506..fd58c5cdfb212bbd087e2803abc213c22611f7db 100644
--- a/lib/string_functions.py
+++ b/lib/opendata_string_functions.py
@@ -21,7 +21,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 # USA.
 
-import codecs
 import datetime
 
 #--------------------------------------------------------------------#
diff --git a/lib/opendata_xml_class.py b/lib/opendata_xml_class.py
new file mode 100644
index 0000000000000000000000000000000000000000..c8c95926676ddfa68684605d010b50a5a3f09473
--- /dev/null
+++ b/lib/opendata_xml_class.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre
+# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+#
+# This file is part of participatorio/opendata
+#
+# participatorio/opendata is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+import MySQLdb
+import codecs
+import datetime
+
+import opendata_string_functions as strf
+import opendata_queries_definition as qry
+
+class OpendataXML:
+    
+    database = None
+    indentation = None
+    level = None
+    dir_results = None
+    filename = None
+    out_file = None
+    
+    #--------------------------------------------------------------------#    
+    def __init__ (self, database, dir_results, filename):
+        self.database = database
+        
+        self.indentation = 0
+        self.level = strf.lvl(self.indentation)
+        
+        self.dir_results = dir_results
+        self.filename = filename
+    #--------------------------------------------------------------------#
+    
+    #--------------------------------------------------------------------#
+    def update_indentation(self, increment):
+        self.indentation=self.indentation+(increment)
+        self.level = strf.lvl(self.indentation)
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def open_file (xml_filename):
+        self.out_file = codecs.open(xml_filename,'w',encoding='utf-8')
+        self.out_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+    #--------------------------------------------------------------------#
+    
+    #--------------------------------------------------------------------#
+    def close_file (self):
+        self.out_file.close()
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_open_tag (self, tag_name, attr_str):
+        self.out_file.write(self.level+"<"+tag_name+attr_str+">"+"\n")
+        self.update_indentation(+1)
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_close_tag (self, tag_name):
+        self.update_indentation(-1)
+        self.out_file.write(self.level+"</"+tag_name+">"+"\n")
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_tag (self, tag_name, info_str, attr_str):
+        if len(info_str) > 0:
+            tag_begin=("<"+tag_name+attr_str+">")
+            tag_end=("</"+tag_name+">")
+            self.out_file.write(self.level+tag_begin+info_str+tag_end+"\n")
+        else:
+            self.out_file.write(self.level+"<"+tag_name+attr_str+"/>"+"\n")
+    #--------------------------------------------------------------------#
+
+    #--------------------------------------------------------------------#
+    def write_comments (self, post_guid):
+        post_comments = db.cursor()
+        post_comments.execute(qry.qry_post_comments, (post_guid,))
+                
+        self.write_open_tag("comentarios",'')
+        for (user_id, user_name, user_username, string, time)\
+            in post_comments:
+            
+            self.write_open_tag("comentario",'')
+            
+            prefix='profile/'
+            user_attr=strf.uidstr(strf.urlparticipa(prefix,user_username))
+            self.write_tag("usuario",user_name,user_attr)
+            self.write_tag("data",strf.datestr(time),'')
+            self.write_tag("mensagem",strf.cdata(string),'')
+            
+            self.write_close_tag("comentario")
+            
+        self.write_close_tag("comentarios")
+        
+        post_comments.close()
+    #--------------------------------------------------------------------#
diff --git a/lib/xml_support_functions.py b/lib/xml_support_functions.py
deleted file mode 100644
index e471e8910944a7f9048fc8e0608ddf458347032b..0000000000000000000000000000000000000000
--- a/lib/xml_support_functions.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre
-# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
-#
-# This file is part of participatorio/opendata
-#
-# participatorio/opendata is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-# USA.
-
-import MySQLdb
-import codecs
-import datetime
-
-import string_functions as strf
-import queries_definition as qry
-
-######################################################################
-# Support functions:
-
-#--------------------------------------------------------------------#
-def open_xml_file (xml_filename):
-    xml_file = codecs.open(xml_filename,'w',encoding='utf-8')
-    xml_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-    return xml_file
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_open_tag (xml, l, tag_name, attr_str):
-    xml.write(strf.lvl(l)+"<"+tag_name+attr_str+">"+"\n")
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_close_tag (xml, l, tag_name):
-    xml.write(strf.lvl(l)+"</"+tag_name+">"+"\n")
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_tag (xml, l, tag_name, info_str, attr_str):
-    if len(info_str) > 0:
-        tag_begin=("<"+tag_name+attr_str+">")
-        tag_end=("</"+tag_name+">")
-        xml.write(strf.lvl(l)+tag_begin+info_str+tag_end+"\n")
-    else:
-        xml.write(strf.lvl(l)+"<"+tag_name+attr_str+"/>"+"\n")
-#--------------------------------------------------------------------#
-
-#--------------------------------------------------------------------#
-def write_comments (db, xml, post_guid):
-    post_comments = db.cursor()
-    post_comments.execute(qry.qry_post_comments, (post_guid,))
-            
-    write_open_tag(xml,4,"comentarios",'')
-    for (user_id, user_name, user_username, string, time) in post_comments:
-        
-        write_open_tag(xml,5,"comentario",'')
-        
-        prefix='profile/'
-        user_attr=strf.uidstr(strf.urlparticipa(prefix,user_username))
-        write_tag(xml,6,"usuario",user_name,user_attr)
-        write_tag(xml,6,"data",strf.datestr(time),'')
-        write_tag(xml,6,"mensagem",strf.cdata(string),'')
-        
-        write_close_tag(xml,5,"comentario")
-        
-    write_close_tag(xml,4,"comentarios")
-    
-    post_comments.close()
-#--------------------------------------------------------------------#
-
-######################################################################