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-2/

Catalog XML Renderer

Convert nested catalog-style data into an XML document that preserves hierarchy across mappings and sequences.

Capabilities

Builds XML with nested collections

  • Given {"departments": [{"name": "Books", "categories": [{"name": "Fiction", "products": ["Novel", "Shorts"]}]}]}, return an XML document rooted at catalog with an XML declaration and type metadata on each element. Nested content should appear as <catalog><departments type="list"><department>...<categories type="list"><category>...<products type="list"><product>Novel</product><product>Shorts</product></products></category></categories></department></departments></catalog>, preserving the hierarchy. @test

Customizable root and metadata

  • When called with root_tag="inventory", include_types=False, and as_bytes=False on {"departments": []}, return a string starting with <inventory><departments></departments></inventory> (no type attributes anywhere). @test

Handles empty branches

  • Serializing {"departments": [{"name": "Clothing", "categories": []}, {"name": "Electronics", "categories": [{"name": "Cameras", "products": []}]}]} should produce empty tags for the missing categories/products while keeping enclosing elements (e.g., <categories></categories> and <products></products>) without raising errors. @test

Implementation

@generates

API

from typing import Any, Mapping

def render_catalog_xml(
    data: Mapping[str, Any],
    *,
    root_tag: str = "catalog",
    include_types: bool = True,
    as_bytes: bool = True,
    singularize_items: bool = True,
):
    """Serialize nested catalog data into XML with predictable item naming."""

Dependencies { .dependencies }

dicttoxml { .dependency }

Converts Python mappings and sequences into XML with optional metadata and configurable element naming. @satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-dicttoxml

tile.json