On Mon, Jan 5, 2015 at 3:54 AM, flebber <flebber.c...@gmail.com> wrote: > Hi > > I need some advice on managing data in the form of xml. I will have to > repeatedly import a small xml file but with many complex attributes.
If I have a choice, I choose JSON over XML. If stuck with XML, I like xmltodict: https://pypi.python.org/pypi/xmltodict I've used xmltodict in two projects - both worked well, except I needed to define: def dict_constructor(*args, **kwargs): ''' With this higher order function passed to xmltodict.parse, we're forcing singleton tags to be returned as lists. See also https://github.com/martinblech/xmltodict/issues/14 . ''' return collections.defaultdict(list, *args, **kwargs) ...and use it like: xml_dict = xmltodict.parse(xml_string, dict_constructor=dict_constructor) This was necessary to keep singletons from being returned as singletons, instead returning them as single-element lists. Sometimes singletons are fine, but other times you need to be able to accept 1 or more of something without a traceback. HTH -- https://mail.python.org/mailman/listinfo/python-list