Skip to content

Commit

Permalink
Yahoo convention: empty elements become '' not {}. Fixes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed Feb 10, 2019
1 parent f8a0434 commit 09136ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_xmljson.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ def test_data(self):
}''', object_pairs_hook=Dict)

eq(json.dumps(data), result)
eq('{"x": ""}', '<x/>')
eq('{"x": "text"}', '<x>text</x>')
eq('{"x": {"key": "val"}}', '<x key="val"></x>')
eq('{"x": {"key": "val", "content": "text"}}', '<x key="val">text</x>')

def test_xml_fromstring(self):
'xml_fromstring=False does not convert types'
Expand Down
3 changes: 3 additions & 0 deletions xmljson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def data(self, root):
else:
result = value.setdefault(child.tag, self.list())
result += self.data(child).values()
# if simple_text, elements with no children or attrs become '', not {}
if not value and self.simple_text:
value = ''
return self.dict([(root.tag, value)])


Expand Down

0 comments on commit 09136ab

Please sign in to comment.