Closed maurosilber closed 8 months ago
The library encodes values as is by default. But you can easily define your own encoding format for any type:
from typing import Annotated
from pydantic import PlainSerializer
from pydantic_xml import BaseXmlModel, attr
XmlBool = Annotated[bool, PlainSerializer(lambda val: str(val).lower())]
class Model(BaseXmlModel):
x: XmlBool = attr()
print(Model.from_xml(b'<Model x="true" />').to_xml().decode())
Yes, I did that, thanks.
But shoudn't it by default encode the Python True
as the string "true"
, which is what the XML specification says?
@maurosilber Yes, that sounds reasonable, fixed it in version 2.3.0.
I'm not sure if this is an invalid XML, but in https://www.w3.org/TR/xmlschema-2/#boolean says that the valid values are
{true, false, 1, 0}
: