#!/usr/bin/python
+from types import StringTypes
from lxml import etree
from StringIO import StringIO
elif isinstance(value, int):
d[key] = unicode(d[key])
elif value is None:
- d.pop(key)
-
+ d.pop(key)
+
+ # element.attrib.update will explode if DateTimes are in the
+ # dcitionary.
+ d=d.copy()
+ for (k,v) in d.iteritems():
+ if not isinstance(v,StringTypes): del d[k]
+ for k in d.keys():
+ if (type(d[k]) != str) and (type(d[k]) != unicode):
+ del d[k]
+
element.attrib.update(d)
def validate(self, schema):
def toxml(self):
return etree.tostring(self.root, encoding='UTF-8', pretty_print=True)
+ # XXX smbaker, for record.load_from_string
def todict(self, elem=None):
if elem is None:
elem = self.root
if child.tag not in d:
d[child.tag] = []
d[child.tag].append(self.todict(child))
- return d
+
+ if len(d)==1 and ("text" in d):
+ d = d["text"]
+
+ return d
def save(self, filename):
f = open(filename, 'w')