Skip to content

Commit

Permalink
fix: Allow short closed elements
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Apr 28, 2024
1 parent eab6bb7 commit 2872c93
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/formats/dataclass/serializers/tree/test_lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class LxmlTreeSerializerTests(TestCase):
def test_render(self):
serializer = LxmlTreeSerializer()
books.book[0].genre = ""
result = serializer.render(books)

etree.indent(result)
Expand All @@ -18,7 +19,7 @@ def test_render(self):
' <book id="bk001" lang="en">\n'
" <author>Hightower, Kim</author>\n"
" <title>The First Book</title>\n"
" <genre>Fiction</genre>\n"
" <genre/>\n"
" <price>44.95</price>\n"
" <pub_date>2000-10-01</pub_date>\n"
" <review>An amazing story of nothing.</review>\n"
Expand Down
3 changes: 2 additions & 1 deletion tests/formats/dataclass/serializers/tree/test_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class XmlTreeSerializerTests(TestCase):
@pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9")
def test_render(self):
serializer = XmlTreeSerializer()
books.book[0].genre = ""
result = serializer.render(books)

ElementTree.indent(result)
Expand All @@ -21,7 +22,7 @@ def test_render(self):
' <book id="bk001" lang="en">\n'
" <author>Hightower, Kim</author>\n"
" <title>The First Book</title>\n"
" <genre>Fiction</genre>\n"
" <genre />\n"
" <price>44.95</price>\n"
" <pub_date>2000-10-01</pub_date>\n"
" <review>An amazing story of nothing.</review>\n"
Expand Down
3 changes: 2 additions & 1 deletion xsdata/formats/dataclass/serializers/tree/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def build(self, obj: T, builder: TreeBuilder):
builder.end(*element)
elif event == XmlWriterEvent.DATA:
data = self.encode_data(element[0])
builder.data(data)
if data:
builder.data(data)
else:
raise XmlHandlerError(f"Unhandled event: `{event}`.")

Expand Down

0 comments on commit 2872c93

Please sign in to comment.