Fields using mapping types (e.g., Dict[str, str], Mapping[str, int], TypedDict) are bound to local element attributes by default. To bind them to sub-elements instead, mark the field with @element().
Default (Attributes)
class Metadata(BaseXmlModel):
tags: dict[str, str] # <metadata tags="key1:val1,key2:val2" />
Using @element
class Metadata(BaseXmlModel):
tags: dict[str, str] = element() # <metadata><tags>...</tags></metadata>
from pydantic_xml import BaseXmlModel, element
from typing import Dict
class Metadata(BaseXmlModel):
tags: Dict[str, str] = element()