comparison 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
comparison
equal deleted inserted replaced
34:a544b376b6f0 35:c45deebb40a5
28 28
29 29
30 @staticmethod 30 @staticmethod
31 def dataForm2xml(form): 31 def dataForm2xml(form):
32 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" 32 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
33 result_xml = ["<form>", "</form>"] 33
34 impl = minidom.getDOMImplementation()
35
36 doc = impl.createDocument(None, "form", None)
37 top_element = doc.documentElement
38
39 #result_xml = ["<form>", "</form>"]
34 if form.instructions: 40 if form.instructions:
35 result_xml.insert(1,"<elem name='instructions' value='%s' type='text' />" % '\n'.join(form.instructions)) 41 elem = doc.createElement('elem')
42 elem.setAttribute('name','instructions')
43 elem.setAttribute('type','text')
44 text = doc.createTextNode('\n'.join(form.instructions))
45 elem.appendChild(text)
46 top_element.appendChild(elem)
36 for field in form.fieldList: 47 for field in form.fieldList:
37 if field.fieldType == 'text-single': 48 if field.fieldType == 'text-single':
38 __field_type = "string" 49 __field_type = "string"
39 elif field.fieldType == 'text-private': 50 elif field.fieldType == 'text-private':
40 __field_type = "password" 51 __field_type = "password"
41 else: 52 else:
42 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) 53 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
43 __field_type = "string_field" 54 __field_type = "string_field"
44 55
45 result_xml.insert(-1,"<elem name='%s' type='%s' label='%s'>" % (field.var, __field_type, field.label)) 56 elem = doc.createElement('elem')
46 57 elem.setAttribute('name', field.var)
47 return '\n'.join(result_xml) 58 elem.setAttribute('type', __field_type)
48 59 elem.setAttribute('label', field.label)
49 60 #text = doc.createTextNode(field.value)
50 61 #elem.appendChild(text)
51 62 top_element.appendChild(elem)
52 pdb.set_trace() 63
64 result = doc.toxml()
65 doc.unlink()
66 return result