CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dicttoxml

Converts a Python dictionary or other native data type into a valid XML string.

86

0.98x
Overview
Eval results
Files

task.mdevals/scenario-10/

Safe XML Payload Serializer

Convert inbound records into XML while keeping element names valid and text content safely escaped.

Capabilities

Escapes text content

  • Serializing {"summary": "Use < & > symbols"} produces XML with an XML declaration (unless the caller disables it), a root element named after the provided root (default payload), and a <summary> element whose text reads Use &lt; &amp; &gt; symbols. @test

Normalizes invalid keys

  • Keys containing spaces or starting with digits are serialized under XML-safe tag names: no output tag contains spaces or starts with a digit, and the original key text remains discoverable either through a normalized tag name or a name attribute. For example, {"123 status": "ok", "product name": "Road Bike"} yields elements that preserve those keys while keeping tag names XML-safe inside the root wrapper. @test

Handles nested structures safely

  • Nested dictionaries and lists preserve hierarchy while still applying XML-safe naming and escaping. Given {"order": {"line items": [{"sku": "AB&C", "detail": "Steel <frame>"}], "notes": "Rush"}}, the output contains nested elements for the list and child dictionaries, with text values escaped (e.g., Steel &lt;frame&gt;) and without invalid tag names (e.g., line items not appearing verbatim as a tag). @test

Implementation

@generates

API

from typing import Any, Mapping

def serialize_payload(payload: Mapping[str, Any], *, root_name: str = "payload", include_declaration: bool = True) -> bytes:
    """Convert the payload into XML bytes with valid element names and escaped text; root tag defaults to 'payload'."""

Dependencies { .dependencies }

dicttoxml { .dependency }

Converts Python data structures into XML with safe tag naming and escaped values.

Install with Tessl CLI

npx tessl i tessl/pypi-dicttoxml

tile.json