Skip to content

MON vs. XML

XML (Extensible Markup Language) is a foundational markup language for documents and data, widely used for its hierarchical structure and extensibility. While powerful for complex document structures, XML can be verbose and challenging to read and write for simple data configurations.

This section outlines the key differences and advantages of MON over XML, particularly for data serialization and configuration.

XML’s verbosity, with its opening and closing tags for every element, can make it difficult to read and write, especially for deeply nested data.

<user>
<name>Alice</name>
<email>alice@example.com</email>
<settings>
<theme>dark</theme>
<notifications>true</notifications>
</settings>
</user>

MON offers a significantly more concise and human-readable syntax for data, reducing boilerplate and improving clarity.

{
user: {
name: "Alice",
email: "alice@example.com",
settings: {
theme: "dark",
notifications: on,
},
},
}

MON Advantages:

  • Conciseness: Eliminates repetitive closing tags, reducing visual clutter.
  • Human-Friendly: Designed for easy reading and writing by developers, unlike XML which often requires specialized tools.
  • Comments: Supports single-line // comments, which are absent in standard XML.

XML relies on external mechanisms like XInclude or XSLT for content reuse and templating, adding layers of complexity.

config.xml
<config>
<default-settings>
<theme>dark</theme>
<notifications>true</notifications>
</default-settings>
<user id="alice">
<name>Alice</name>
<!-- Imagine duplicating settings here or using XInclude -->
<settings>
<theme>dark</theme>
<notifications>true</notifications>
</settings>
</user>
</config>

MON provides powerful, built-in features for data reuse, allowing you to define data once and apply it across your configurations with ease.

{
&default_settings: {
theme: "dark",
notifications: on,
},
user_alice: {
name: "Alice",
...*default_settings,
},
}

MON Advantages:

  • Native Composition: Anchors, aliases, and spreads are core language features, simplifying data reuse.
  • Reduced Boilerplate: Avoids the need for external templating engines or complex XML transformations.

XML uses DTDs, XML Schema (XSD), or Relax NG for schema definition and validation, which are powerful but often complex and verbose.

<!-- user.xsd -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="user">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

MON integrates schema validation directly into the language, offering a more concise and developer-friendly way to ensure data integrity.

{
User: #struct {
name(String),
email(String),
},
alice :: User = {
name: "Alice",
email: "alice@example.com",
},
}

MON Advantages:

  • Concise Schema Definition: Define data structures directly within the MON file, reducing overhead.
  • Integrated Validation: Validation is a core language feature, not a separate layer.
  • Developer-Friendly: Easier to learn and use than complex XML Schema languages.

XML projects often manage modularity through external tools, entity declarations, or complex build processes.

MON offers a straightforward module system for organizing multi-file configurations and sharing types/data across files, designed for modern development workflows.

config.mon
import * as schemas from "./schemas.mon"
{
db_config :: schemas.Database = {
host: "localhost",
port: 5432,
},
}

MON Advantages:

  • Native Imports: Explicit import statements for clear dependency management.
  • Simplified Modularity: Streamlines the process of splitting large configurations into manageable, reusable files.

While XML remains a robust choice for document-centric applications and complex data interchange where strict validation and extensibility are paramount, MON offers a superior experience for data serialization and configuration files. Its focus on human readability, native reusability, and integrated schema validation makes it a compelling alternative for developers seeking clarity and efficiency.