JSON gets most of the attention in modern web development, but XML is nowhere near gone. Sitemaps, RSS feeds, SVG files, Maven build configs, Android layouts, SOAP APIs, Microsoft Office documents, and dozens of enterprise integration formats all use XML. Knowing how to read, write, and format XML is still a practical skill — and knowing when XML is the right choice for a new project is a design decision worth making deliberately.
The XML Formatter on DevToolShack lets you pretty-print and validate XML in your browser instantly, with no server upload. The JSON to XML converter handles converting JSON data to XML when a system requires it. Here is what to know about both the format and the tools.
XML Structure: The Basics
XML (Extensible Markup Language) represents data as a tree of elements enclosed in opening and closing tags. Every XML document has a single root element. Elements can contain other elements, text content, or both. Attributes provide additional metadata on opening tags.
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101" available="true">
<title>Clean Code</title>
<author>Robert C. Martin</author>
<price currency="USD">32.99</price>
</book>
<book id="bk102" available="false">
<title>The Pragmatic Programmer</title>
<author>Andrew Hunt</author>
<price currency="USD">38.50</price>
</book>
</catalog>
A few structural rules that XML enforces strictly, unlike HTML:
- Every opening tag must have a matching closing tag (or be self-closing:
<br />). - Tags are case-sensitive.
<Title>and<title>are different elements. - Attributes must be quoted.
available=trueis invalid;available="true"is correct. - There must be exactly one root element. A document with two top-level elements is not valid XML.
- Special characters in text content must be escaped:
&for&,<for<,>for>.
When XML Is Still the Right Choice
JSON has replaced XML for most REST APIs and general data interchange — it's smaller, easier to read, and maps directly to JavaScript objects. But XML has genuine strengths that keep it relevant in specific contexts.
When you need schema validation. XML Schema Definition (XSD) and RELAX NG provide rich, standardized ways to define and validate the structure of an XML document. JSON Schema exists but is less mature and less universally supported. For enterprise data exchange where strict contract enforcement matters, XML's validation ecosystem is more battle-tested.
When you need namespaces. XML namespaces allow multiple vocabularies to coexist in a single document without naming conflicts. This is essential in SOAP web services, where a single message might mix elements from multiple specifications, and in SVG, where XML elements from different namespaces carry different meanings.
When the tooling requires it. Maven, Gradle (pre-Kotlin DSL), Android layout files, Microsoft Office Open XML (.docx, .xlsx), InDesign IDML, and many CI/CD configuration formats use XML. You don't choose XML here; you work with it because the platform requires it.
When you need document-centric data. XML handles mixed content well: text with embedded markup, like a paragraph containing bold and italic spans, is natural in XML. JSON has no equivalent. For publishing workflows, content management, and document formats, XML (particularly DITA and DocBook) remains the standard.
Sitemaps and RSS/Atom feeds. These formats are defined in XML and aren't going anywhere. Any CMS or web platform that generates sitemaps or feeds produces XML.
When to Choose JSON Instead
For new REST APIs, configuration files that developers will edit by hand, and data interchange between web services you control, JSON is almost always the better choice. It's less verbose, parses natively in JavaScript, and has wide library support in every language. The post on JSON vs CSV vs XML covers the trade-offs in detail.
Formatting Minified or Broken XML
XML produced by code generators, APIs, and export tools often arrives as a single long line or with inconsistent indentation. Reading it in that state is painful. The XML Formatter on DevToolShack pretty-prints any XML with consistent indentation, making the tree structure immediately readable. It also validates the XML and reports parse errors, so you can see immediately whether a document is well-formed before trying to process it.
Common formatting issues the tool catches:
- Missing closing tags (the parser will point to the line where the structure breaks)
- Unescaped ampersands and angle brackets in text content
- Invalid characters in attribute values
- Multiple root elements
- Encoding declaration mismatches
Converting Between JSON and XML
When you need to bridge a JSON-based system and an XML-based one, the JSON to XML converter on DevToolShack converts JSON objects to equivalent XML. The mapping follows a straightforward convention: JSON object keys become XML element names, string and number values become element text content, and arrays become repeated elements with the same tag name.
/* JSON input */
{
"user": {
"name": "Alice",
"role": "admin",
"tags": ["developer", "reviewer"]
}
}
/* XML output */
<root>
<user>
<name>Alice</name>
<role>admin</role>
<tags>developer</tags>
<tags>reviewer</tags>
</user>
</root>
One thing to be aware of: JSON keys that start with numbers or contain spaces are not valid XML element names. The converter handles this by sanitizing invalid characters, but you should review the output when the JSON keys are unusual.
XPath: Querying XML Data
XPath is to XML what JSONPath is to JSON: a query language for extracting values from a document tree. It is widely supported in languages like Python (via lxml), Java, PHP, and in command-line tools like xmllint and xpath. A basic XPath expression like //book[@available='true']/title would select the title of every book with available="true" from the catalog example above.
XPath is used extensively in XSLT (for transforming XML to other formats), in Selenium test selectors, and in XML-based CI pipeline configurations. If you work with XML regularly, investing time in XPath syntax pays dividends.
XML in the Build Tool Ecosystem
Maven's pom.xml is one of the most widely-read XML files in the Java ecosystem. Android's layout XML files define UI structures that are compiled into binary resources. GitHub Actions and some other CI systems use YAML, but Jenkins pipelines often use XML. Knowing how to read and edit these files efficiently is practical knowledge, even if you'd never choose XML for a new API.
For a comparison of JSON, CSV, and XML as data formats for new projects, see JSON vs CSV vs XML: Which Data Format Should You Use? and for converting JSON data for XML-based systems, the JSON to XML and YAML to JSON tools cover the most common conversion paths.