Created
September 11, 2011 16:11
-
-
Save refnode/1209773 to your computer and use it in GitHub Desktop.
XML2Dict Patch for handling empty text, returned as None. NoneType has no String Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/encoder.py b/encoder.py | |
index 9b4dc41..f5c1829 100644 | |
--- a/encoder.py | |
+++ b/encoder.py | |
@@ -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) | |
else: | |
cdict = self._make_dict(ctag, ctree, cattr) |
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
Better import for elementtree
try:
import cElementTree as etree
except ImportError:
try:
import xml.etree.ElementTree as etree
except ImportError:
from elementtree import ElementTree as etree