DevTools Logo

XML, TOML & Config Formats Cheat Sheet

Quick reference for configuration formats: XML structures, TOML tables/arrays, and when to choose each serialization.

Data Formats
xml
toml
config

XML, JSON, YAML, and TOML are the four main structured formats. XML is verbose and document-oriented (with attributes + namespaces); TOML is minimal and human-friendly for config files (INI evolved); JSON/YAML are the generic interchange pair.

XML Basics

XML is a tree of elements with attributes. Well-formedness requires exactly one root element, closed tags, and quoted attributes.

xml
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book category="fiction">
    <title>Book A</title>
    <price currency="USD">8.95</price>
  </book>
  <book category="reference">
    <title>Book C</title>
    <price currency="USD">8.99</price>
  </book>
</bookstore>
Table
ConceptSyntaxExample
Declaration<?xml ...?><?xml version="1.0"?>
Element<name>...</name><title>Book A</title>
Attributename="value"category="fiction"
Self-closing<empty /><linebreak />
Comment<!-- ... --><!-- generated -->
CDATA<![CDATA[...]]>Raw text without escaping
Namespacexmlns:prefixxmlns:xsd="http://www.w3.org/2001/XMLSchema"

TOML Basics

TOML uses key-value pairs, tables ([name]), and arrays of tables ([[name]]). It is strict about types and does not allow tabs for indentation.

toml
title = "My App"
version = "1.2.0"
debug = false

[server]
host = "0.0.0.0"
port = 8080
max_connections = 100

[database]
driver = "postgres"
url = "postgres://user:pass@localhost:5432/app"

[features.flags]
enable_ml = true
max_items = 50

[[servers]]
name = "east"
ip = "10.0.0.1"

[[servers]]
name = "west"
ip = "10.0.0.2"
Table
ConstructSyntaxExample
Key-valuekey = valueport = 8080
Table[table][server]
Nested table[a.b.c][database.pool]
Array of tables[[name]][[servers]] (repeatable)
Inline table{ key = value }point = { x = 1, y = 2 }
Array[1, 2, 3]ports = [80, 443]
Multi-line string"""..."""Long text blocks

Format Comparison

Table
CharacteristicJSONYAMLTOMLXML
CommentsNo##<!-- -->
Strings must be quotedYesSometimesYesNo
Type inferenceNoYes (dates, numbers)YesNo (all text)
Best forAPIs, data interchangeConfig, CI filesConfig filesDocuments, SOAP, SVG
Namespaces/attributesNoNoNoYes
Human factorMachine-friendlyIndentation-sensitiveMinimal, INI-likeVerbose

Common Pitfalls

[!WARNING] YAML and TOML both auto-infer types — a value like port: 8080 becomes a number and version: 1.0 may be parsed as a float. Quote values when you need strings.

[!TIP] Use TOML for application config (it's the format of Cargo, pyproject, and many tools), JSON for API payloads, and XML only when the ecosystem requires it (SOAP, SVG, sitemaps).

References