Convert XML to TOML
Max file size 100mb.
XML vs TOML Format Comparison
| Aspect | XML (Source Format) | TOML (Target Format) |
|---|---|---|
| Format Overview |
XML
Extensible Markup Language
W3C standard markup language designed for storing and transporting structured data. Uses self-describing tags with a strict hierarchical tree structure. Widely used in enterprise systems, web services (SOAP), configuration files (Maven, Spring, Android), and data interchange between heterogeneous platforms. W3C Standard Enterprise Data |
TOML
Tom's Obvious, Minimal Language
A minimal configuration file format designed by Tom Preston-Werner (GitHub co-founder) in 2013. TOML aims to be easy to read due to obvious semantics, mapping unambiguously to a hash table. It supports typed values (strings, integers, floats, booleans, datetimes), tables, and arrays of tables. Used by Rust (Cargo.toml), Python (pyproject.toml), and Hugo. Configuration Typed Values |
| Technical Specifications |
Standard: W3C XML 1.0 (5th Edition) / XML 1.1
Encoding: UTF-8, UTF-16 (declared in prolog) Format: Tag-based hierarchical tree structure Validation: DTD, XML Schema (XSD), RELAX NG Extension: .xml |
Standard: TOML v1.0.0 (January 2021)
Encoding: UTF-8 (required) Format: Key-value pairs with tables and arrays Types: String, Integer, Float, Boolean, Datetime, Array, Table Extension: .toml |
| Syntax Examples |
XML uses nested tags for structure: <?xml version="1.0"?>
<project>
<name>MyApp</name>
<version>2.0</version>
<dependencies>
<dependency>spring-core</dependency>
<dependency>hibernate</dependency>
</dependencies>
</project>
|
TOML uses key-value pairs and sections: [project] name = "MyApp" version = "2.0" [[project.dependencies]] name = "spring-core" [[project.dependencies]] name = "hibernate" |
| Content Support |
|
|
| Advantages |
|
|
| Disadvantages |
|
|
| Common Uses |
|
|
| Best For |
|
|
| Version History |
Created: 1996 by W3C (Jon Bosak et al.)
XML 1.0: 1998 (W3C Recommendation) XML 1.1: 2004 (Unicode 2.0+ support) Current: XML 1.0 Fifth Edition (2008) Status: Stable W3C Recommendation |
Created: 2013 by Tom Preston-Werner
v0.1.0: 2013 (initial public release) v0.5.0: 2018 (major refinements) v1.0.0: January 2021 (stable specification) Status: Stable (v1.0.0) |
| Software Support |
Java: JAXP, DOM, SAX, StAX, JAXB
Python: xml.etree, lxml, BeautifulSoup .NET: System.Xml, XDocument, XmlReader Tools: XMLSpy, Oxygen XML, xsltproc |
Rust: toml crate (reference parser)
Python: tomllib (stdlib 3.11+), tomli, tomlkit Go: BurntSushi/toml, pelletier/go-toml JavaScript: @iarna/toml, smol-toml |
Why Convert XML to TOML?
Converting XML to TOML transforms verbose, tag-heavy configuration files into clean, minimal, and human-friendly configuration. XML's angle brackets, closing tags, and attribute syntax add significant overhead for simple key-value configuration, whereas TOML was designed from the ground up to be a configuration format that maps directly to a hash table with native typed values.
This conversion is especially valuable when migrating legacy Java or .NET applications that use XML configuration files (such as Maven pom.xml settings, Spring application properties, or .NET app.config) to modern toolchains that prefer TOML. Projects using Rust (Cargo.toml), Python (pyproject.toml), or Hugo can benefit from extracting configuration embedded in XML and placing it in the idiomatic TOML format.
Our converter intelligently maps XML structures to TOML equivalents: root elements become top-level tables, nested elements become sub-tables using dotted keys or [section] headers, repeated elements become arrays of tables ([[array]]), and text content is assigned as typed values (strings, integers, floats, booleans) where possible. Attributes are preserved as additional keys within their parent table.
TOML's native type system is a significant advantage over XML for configuration. While XML treats all values as strings (requiring schema-based type annotation), TOML distinguishes between strings ("value"), integers (42), floats (3.14), booleans (true/false), and datetimes (1979-05-27T07:32:00Z) natively. This eliminates an entire category of type-related bugs in configuration parsing.
Key Benefits of Converting XML to TOML:
- Dramatic Size Reduction: Eliminate closing tags, angle brackets, and XML boilerplate for 50-70% smaller files
- Native Type Safety: TOML's built-in types (int, float, bool, datetime) prevent string-based type errors
- Human Editability: TOML was designed for humans to read and write without specialized editors
- Comment Support: Add inline documentation with # comments (XML comments are verbose)
- Modern Toolchain Adoption: Compatible with Cargo, pyproject.toml, Hugo, and other modern tools
- Unambiguous Parsing: TOML maps 1:1 to a hash table, eliminating XML's attribute vs. element ambiguity
- No Security Risks: TOML has no equivalent of XXE attacks or billion laughs vulnerabilities
Practical Examples
Example 1: Application Configuration
Input XML file (app-config.xml):
<?xml version="1.0"?>
<config>
<server>
<host>localhost</host>
<port>8080</port>
<debug>true</debug>
</server>
<database>
<driver>postgresql</driver>
<host>db.example.com</host>
<port>5432</port>
<name>myapp_prod</name>
<pool_size>10</pool_size>
</database>
</config>
Output TOML file (app-config.toml):
[server] host = "localhost" port = 8080 debug = true [database] driver = "postgresql" host = "db.example.com" port = 5432 name = "myapp_prod" pool_size = 10
Example 2: Build Dependencies
Input XML file (dependencies.xml):
<package>
<name>my-library</name>
<version>0.3.1</version>
<authors>
<author>Alice Smith</author>
<author>Bob Jones</author>
</authors>
<dependencies>
<dependency name="serde" version="1.0" features="derive"/>
<dependency name="tokio" version="1.28" features="full"/>
</dependencies>
</package>
Output TOML file (Cargo.toml):
[package]
name = "my-library"
version = "0.3.1"
authors = ["Alice Smith", "Bob Jones"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.28", features = ["full"] }
Example 3: Logging Configuration
Input XML file (logging.xml):
<logging>
<level>info</level>
<format>json</format>
<outputs>
<output type="file" path="/var/log/app.log" rotate="daily"/>
<output type="console" colorize="true"/>
</outputs>
<filters>
<filter module="http" level="warn"/>
<filter module="db" level="debug"/>
</filters>
</logging>
Output TOML file (logging.toml):
[logging] level = "info" format = "json" [[logging.outputs]] type = "file" path = "/var/log/app.log" rotate = "daily" [[logging.outputs]] type = "console" colorize = true [[logging.filters]] module = "http" level = "warn" [[logging.filters]] module = "db" level = "debug"
Frequently Asked Questions (FAQ)
Q: What is XML format?
A: XML (Extensible Markup Language) is a W3C standard for structuring, storing, and transporting data. It uses custom tags with a strict hierarchical tree structure. XML is used in enterprise integration (SOAP), configuration files (Maven pom.xml, Spring, Android), document formats (XHTML, SVG, DOCX internals), financial data (XBRL), and healthcare (HL7). Unlike HTML, XML tags are self-describing and user-defined.
Q: What is TOML format?
A: TOML (Tom's Obvious, Minimal Language) is a configuration file format created by Tom Preston-Werner in 2013. It uses key-value pairs grouped into tables (sections), with native support for typed values including strings, integers, floats, booleans, datetimes, arrays, and tables. TOML is designed to be unambiguous and map directly to a hash table. It reached v1.0.0 in January 2021 and is used by Rust (Cargo.toml), Python (pyproject.toml), and Hugo.
Q: How are XML elements converted to TOML tables?
A: XML parent elements with child elements become TOML tables (e.g., <server> becomes [server]). Leaf elements with text content become key-value pairs. Repeated sibling elements (like multiple <dependency> tags) become arrays of tables using TOML's [[array]] syntax. Attributes are converted to additional keys within the table.
Q: Does the conversion preserve XML data types?
A: Yes, the converter attempts to infer appropriate TOML types from XML text content. Numeric values are converted to TOML integers or floats, "true" and "false" become TOML booleans, ISO 8601 date strings become TOML datetimes, and all other values remain as TOML strings. This type inference eliminates the need for manual type annotations.
Q: What happens to XML attributes during conversion?
A: XML attributes are converted to key-value pairs within their parent table. For example, <output type="file" path="/log"> becomes keys type = "file" and path = "/log" under the appropriate TOML table. If an element has both attributes and text content, the text content is stored under a special key.
Q: Can deeply nested XML be represented in TOML?
A: TOML supports nested tables using dotted keys (a.b.c = "value") or nested section headers ([a.b.c]). However, TOML is best suited for configuration data with 2-3 levels of nesting. Extremely deep XML hierarchies (5+ levels) may require flattening with dotted key names to maintain readability in TOML format.
Q: Is TOML suitable for all XML use cases?
A: TOML is ideal for configuration files and simple structured data but is not a replacement for all XML use cases. It is not suitable for document markup (use HTML/Markdown), deeply hierarchical data (use JSON/YAML), or enterprise integration protocols (SOAP requires XML). TOML excels specifically in the configuration file domain.
Q: What tools can edit the resulting TOML files?
A: TOML files are plain text and can be edited with any text editor. Most modern editors provide TOML syntax highlighting: VS Code (Even Better TOML extension), IntelliJ IDEA (built-in), Vim/Neovim (vim-toml), and Sublime Text. Programmatic access is available via tomllib in Python 3.11+, the toml crate in Rust, and BurntSushi/toml in Go.