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 in d.keys():
+ if (type(d[k]) != str) and (type(d[k]) != unicode):
+ del d[k]
+
element.attrib.update(d)
def validate(self, schema):
if child.tag not in d:
d[child.tag] = []
d[child.tag].append(self.todict(child))
- return d
+ return d
+
+ # XXX smbaker, for record.load_from_string
+ def todict2(self, elem=None):
+ if elem is None:
+ elem = self.root
+ d = {}
+ d.update(elem.attrib)
+ d['text'] = elem.text
+ for child in elem.iterchildren():
+ if child.tag not in d:
+ d[child.tag] = []
+ d[child.tag].append(self.todict2(child))
+
+ if len(d)==1 and ("text" in d):
+ d = d["text"]
+
+ return d
def save(self, filename):
f = open(filename, 'w')