ModernCalcs

XML to TOML


[database]
host = "localhost"
port = 5432
name = "mydb"

[server]
host = "0.0.0.0"
port = 8080
debug = true

Child elements of the root element become TOML sections. Nested elements become [table] headers. Repeated elements become [[array of tables]]. Numeric and boolean string values are type-inferred.

XML to TOML: Migrate Legacy XML Config to Modern TOML Format

Many older applications use XML for configuration (Spring, Maven, Ant, Log4j). Modern tools prefer TOML for its readability and type system. This converter handles the common case of XML config files with a hierarchical structure — converting child elements to TOML sections, repeated elements to arrays of tables, and inferring types from text content.

Formula
<config> <database> <host>localhost</host> <port>5432</port> </database> </config> → TOML: [database] host = "localhost" port = 5432

Integer and boolean text values are type-inferred. XML attributes are not preserved in TOML output.

XML vs TOML Philosophy

XML was designed for mixed content and arbitrary nesting. TOML was designed specifically for configuration, with a flat key-value structure and clear section headers. The conversion works best when the XML follows config conventions (no mixed content, no attributes for critical data). Complex XML documents — like HTML or SVG — do not convert meaningfully to TOML.

Recommended Workflow for Complex XML

For complex XML, a two-step approach is safer: (1) Use this site's XML-to-JSON converter to get the full structure with attributes preserved as @attr keys. (2) Review and edit the JSON to match TOML's flat-ish structure. (3) Use a JSON-to-TOML tool to produce the final TOML. This gives you visibility into the intermediate representation.

Type Inference

The converter reads text content of leaf elements and infers TOML types: '5432' → integer 5432, '3.14' → float 3.14, 'true'/'false' → TOML boolean. Everything else becomes a quoted string. This matches what you would type by hand when creating the TOML from scratch — no quotes needed around numbers and booleans.

Conversion Rules

  • Child elements → TOML [section] headers
  • Repeated same-name children → [[array_of_tables]]
  • Leaf text values → key = value pairs
  • Number/boolean strings → typed TOML values
  • XML attributes → dropped (not preserved)

Frequently Asked Questions

What XML structure maps well to TOML?

XML config files with a clear hierarchy map well to TOML. A root element with section child elements (like ......) becomes TOML [database] and [server] sections. Repeated child elements become [[array_of_tables]]. Leaf elements with text content become key = value pairs.

How are XML attributes handled?

XML attributes are dropped during the XML-to-TOML conversion. TOML has no equivalent of XML attributes — values live as keys. If your XML uses attributes for important data, convert to JSON first (which preserves attributes as @attr keys), then manually restructure the JSON before converting to TOML.

How are type strings inferred?

The converter inspects text content of leaf elements: integer strings (123) become TOML integers, decimal strings (3.14) become floats, 'true'/'false' become TOML booleans. All other values become quoted TOML strings. This handles the common case where XML stores typed values as text.

What are the limitations?

Deeply nested XML (more than two levels deep) may not convert correctly — the TOML serializer handles one level of [section] nesting. Mixed content (elements with both text and child elements) drops the text. XML attributes are not converted. For complex structures, convert to JSON first, review the JSON, then convert JSON to TOML.