#!/usr/bin/python
+from types import StringTypes
from lxml import etree
from StringIO import StringIO
# 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]
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
-
- # 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"]