diff tools/xml_tools.py @ 35:c45deebb40a5

Wix: Registration form management (not finished yet) - impoved xml conversion in xml_tools
author Goffi <goffi@goffi.org>
date Sun, 13 Dec 2009 20:24:48 +1100
parents b9bb5d8e0cc7
children a61beb21d16d
line wrap: on
line diff
--- a/tools/xml_tools.py	Sun Dec 13 18:36:20 2009 +1100
+++ b/tools/xml_tools.py	Sun Dec 13 20:24:48 2009 +1100
@@ -30,9 +30,20 @@
     @staticmethod
     def dataForm2xml(form):
         """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
-        result_xml = ["<form>", "</form>"]
+        
+        impl = minidom.getDOMImplementation()
+
+        doc = impl.createDocument(None, "form", None)
+        top_element = doc.documentElement
+        
+        #result_xml = ["<form>", "</form>"]
         if form.instructions:
-            result_xml.insert(1,"<elem name='instructions' value='%s' type='text' />" % '\n'.join(form.instructions))
+            elem = doc.createElement('elem')
+            elem.setAttribute('name','instructions')
+            elem.setAttribute('type','text')
+            text = doc.createTextNode('\n'.join(form.instructions))
+            elem.appendChild(text)
+            top_element.appendChild(elem)
         for field in form.fieldList:
             if field.fieldType == 'text-single':
                 __field_type = "string"
@@ -42,11 +53,14 @@
                 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
                 __field_type = "string_field"
             
-            result_xml.insert(-1,"<elem name='%s' type='%s' label='%s'>" % (field.var, __field_type, field.label))
-
-        return '\n'.join(result_xml)
-
-        
-        
-        
-        pdb.set_trace()
+            elem = doc.createElement('elem')
+            elem.setAttribute('name', field.var)
+            elem.setAttribute('type', __field_type)
+            elem.setAttribute('label', field.label)
+            #text = doc.createTextNode(field.value)
+            #elem.appendChild(text)
+            top_element.appendChild(elem)
+            
+        result = doc.toxml()
+        doc.unlink()
+        return result