Converts a Python dictionary or other native data type into a valid XML string.
86
Generate an XML document for audit records where every element is annotated with its original Python type and date/boolean values are normalized for downstream consumers.
id=7, active=True, and created_at=datetime(2024, 1, 3, 15, 45, tzinfo=timezone.utc) returns an XML string where each element includes a type attribute, booleans render as true/false, and the datetime uses ISO-8601 with its timezone offset. @test{"flags": {"beta": False}, "window": {"start": datetime(2023, 12, 1, 8, 0, 0), "end": datetime(2023, 12, 1, 9, 0, 0)}}, the generated XML nests those sections and retains type annotations for all inner elements, with datetime values formatted in ISO-8601. @test@generates
from datetime import datetime, timezone
from typing import Iterable, Mapping, Any
def build_audit_xml(records: Iterable[Mapping[str, Any]]) -> str:
"""Return an XML document string that type-annotates elements and normalizes datetimes/booleans."""Converts Python objects to XML while adding type attributes and normalizing datetime/boolean values. @satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-dicttoxmldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10