Converts a Python dictionary or other native data type into a valid XML string.
86
Generate an XML feed from product records for partner ingestion.
<inventory> root, emitting each entry as a <product> element with sequential id attributes when ID annotations are enabled. Nested dictionaries become nested tags. @testinclude_types is true, element nodes carry type metadata attributes; when false, no type metadata appears anywhere in the output. @testuse_cdata is true, string values are wrapped in CDATA sections instead of being entity-escaped. @testas_bytes is true, the function returns bytes that include the XML declaration; otherwise it returns a Unicode string without changing the content. @test@generates
from typing import Iterable, Mapping, Any, Union
def build_inventory_xml(
products: Iterable[Mapping[str, Any]],
*,
with_ids: bool = True,
include_types: bool = True,
use_cdata: bool = False,
as_bytes: bool = False
) -> Union[bytes, str]:
"""Convert products into an inventory XML feed."""Converts Python objects to XML with controllable root naming, id metadata, type annotations, CDATA wrapping, and byte/string outputs.
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