What XML formatting does
XML formatting adds indentation to nested elements, line breaks between sibling elements, and consistent attribute formatting. A minified XML string that spans one line becomes a tree-structured document where hierarchy is immediately clear.
Beyond formatting, XML validators check that the document is well-formed: all tags are properly opened and closed, attribute values are quoted, and no illegal characters appear in tag names. Well-formedness is a strict requirement — unlike HTML, a browser won't try to correct malformed XML.
The Irreva XML Formatter parses the XML and reformats it with consistent indentation. Validation errors are shown with the line number and a description of the problem.
Common XML errors
Missing closing tags are the most common XML error. Every opening tag must have a corresponding closing tag (or use self-closing syntax: <br/>). Unlike HTML, XML has no optional end tags.
Unescaped special characters cause parsing failures. The characters <, >, &, ', and " have special meaning in XML. To use them in text content or attribute values, use the entity references: <, >, &, ', and ".
Multiple root elements are also invalid. A valid XML document must have exactly one root element that contains all other elements. Two top-level elements without a parent is a well-formedness error.
- Unclosed tags: <tag> with no </tag>
- Unescaped < or & in text content
- Attribute values not quoted
- Multiple root elements
- Lowercase/uppercase mismatch: XML is case-sensitive
- Invalid characters in element names
XML vs JSON — when to use each
JSON has largely replaced XML for new REST APIs because it's less verbose, easier to read, and directly maps to data structures in most languages. But XML remains dominant in several areas: SOAP web services, enterprise integration, Microsoft Office file formats (DOCX, XLSX are zip files containing XML), SVG vector graphics, and Android layouts.
XML has features JSON lacks: XML Schema Definition (XSD) for rigorous data validation, namespaces for combining elements from different vocabularies, XSLT for transforming XML to other formats, and XPath for querying into an XML document.
For configuration files, XML was long the standard (Spring, Maven, web.xml). YAML and JSON have replaced XML in many newer tools, but XML configuration is still common in Java and .NET ecosystems.
