Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
XML2Dict Patch for handling empty text, returned as None. NoneType has no String Methods
diff --git a/ b/
index 9b4dc41..f5c1829 100644
--- a/
+++ b/
@@ -34,9 +34,12 @@ class XML2Dict(object):
ctag = child.tag
cattr = child.attrib
ctree = self._parse_node(child)
+ ctext = child.text
+ if ctext:
+ ctext = ctext.strip().encode(self._coding)
if not ctree:
- cdict = self._make_dict(ctag, child.text.strip().encode(self._coding), cattr)
+ cdict = self._make_dict(ctag, ctext, cattr)
cdict = self._make_dict(ctag, ctree, cattr)

This comment has been minimized.

Copy link
Owner Author

@refnode refnode commented Sep 11, 2011

Better import for elementtree

import cElementTree as etree
except ImportError:
import xml.etree.ElementTree as etree
except ImportError:
from elementtree import ElementTree as etree


This comment has been minimized.

Copy link

@mcspring mcspring commented Sep 13, 2011

Thanks for your path, I have just update the package follow your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment