tessl install tessl/pypi-dicttoxml@1.7.0Converts a Python dictionary or other native data type into a valid XML string.
Agent Success
Agent success rate when using this tile
86%
Improvement
Agent success rate improvement when using this tile compared to baseline
0.99x
Baseline
Agent success rate without this tile
87%
A utility that converts Python mappings into XML with controllable declaration visibility, root wrapping, and encoding metadata.
{ "title": "Atlas", "version": 1 } and default options, returns XML that begins with an XML declaration containing the encoding and wraps all fields in a <response> root element. @test{ "status": "ok" } and options include_declaration=False and wrap_root=False, returns XML without any XML declaration and without a top-level wrapper element, containing only the element for status. @test{ "item": "value" } and root_name="dataset", include_declaration=True, wrap_root=True, the XML encloses entries under <dataset> instead of the default root tag. @test{ "note": "cafe" } and include_declaration=True, encoding="ISO-8859-1":
include_encoding=True, the XML declaration includes encoding="ISO-8859-1".include_encoding=False, the XML declaration omits any encoding attribute while keeping the declaration line. @test@generates
from typing import Any, Mapping
def format_xml(
payload: Mapping[str, Any],
*,
root_name: str = "response",
include_declaration: bool = True,
wrap_root: bool = True,
encoding: str = "UTF-8",
include_encoding: bool = True,
return_bytes: bool = False,
) -> str | bytes:
"""
Convert the payload to XML while honoring declaration visibility, root wrapping, and encoding metadata options.
Returns a bytes object when return_bytes is True; otherwise returns a string.
"""Provides XML conversion for Python data structures.