martinblech / xmltodict

Python module that makes working with XML feel like you are working with JSON
MIT License
5.49k stars 462 forks source link

Bug: Booleans are not unparsed correctly in XML attributes #303

Open BrendanJM opened 2 years ago

BrendanJM commented 2 years ago

Example:

print(xmltodict.unparse({'a': {'@foo': True}}))

output:

<?xml version="1.0" encoding="utf-8"?>
<a foo="True"></a>

According to the XML Schema Specification the correct output should be

<?xml version="1.0" encoding="utf-8"?>
<a foo="true"></a>

Related issue only fixed boolean unparsing in children, but did not resolve attributes: https://github.com/martinblech/xmltodict/issues/179

horvatha commented 2 years ago

I've the same problem. I've created two pull requests. One does just the minimal changes to solve the problem, the other also removes Python 2 compatibility tricks. I hope that one of them will be merged. :-)