defformat_as_xml(obj:Any,root_tag:str='examples',item_tag:str='example',include_root_tag:bool=True,none_str:str='null',indent:str|None=' ',)->str:"""Format a Python object as XML. This is useful since LLMs often find it easier to read semi-structured data (e.g. examples) as XML, rather than JSON etc. Supports: `str`, `bytes`, `bytearray`, `bool`, `int`, `float`, `date`, `datetime`, `Mapping`, `Iterable`, `dataclass`, and `BaseModel`. Args: obj: Python Object to serialize to XML. root_tag: Outer tag to wrap the XML in, use `None` to omit the outer tag. item_tag: Tag to use for each item in an iterable (e.g. list), this is overridden by the class name for dataclasses and Pydantic models. include_root_tag: Whether to include the root tag in the output (The root tag is always included if it includes a body - e.g. when the input is a simple value). none_str: String to use for `None` values. indent: Indentation string to use for pretty printing. Returns: XML representation of the object. Example: ```python {title="format_as_xml_example.py" lint="skip"} from pydantic_ai.format_as_xml import format_as_xml print(format_as_xml({'name': 'John', 'height': 6, 'weight': 200}, root_tag='user')) ''' <user> <name>John</name> <height>6</height> <weight>200</weight> </user> ''' ``` """el=_ToXml(item_tag=item_tag,none_str=none_str).to_xml(obj,root_tag)ifnotinclude_root_tagandel.textisNone:join=''ifindentisNoneelse'\n'returnjoin.join(_rootless_xml_elements(el,indent))else:ifindentisnotNone:ElementTree.indent(el,space=indent)returnElementTree.tostring(el,encoding='unicode')