XML Formatter
Paste XML. Format it, check it as you type, get the JSON. Nothing leaves your browser.
- 0
- Lines
- 0
- Elements
- 0
- Errors
On this page
About XML Formatter
Updated
What is an XML Formatter?
An XML Formatter takes your XML and gives it clean, consistent indentation, so it is easy to read. XML (Extensible Markup Language) is a markup language for storing and transporting data, and the base of formats like SVG, RSS, SOAP, XSLT and many configuration files.
How to use this tool
Paste your XML into the editor and press Format. The tool checks your XML as you type: mismatched or unclosed tags, unquoted or repeated attributes, a bare & or <, and more than one root element. It rings the exact spot, gives the line and column, and says how to fix it. Lines that Format changed stay marked until you edit them.
Summarize XML
The Result pane names the root element and counts the elements, attributes, namespaces, comments and CDATA sections, and shows the nesting depth. Open Notes to see the root and each of its children next to their lines.
Convert XML to JSON
Open the JSON tab in the Result header to see your XML as JSON. Copy and Download then take the JSON. Child elements become arrays, attributes go under $ (or into the object itself, if you choose that in Options), and text next to children goes under _.
Customization
Open Options to set the indent, keep short text on the same line as its tags, write empty elements as <tag />, sort attributes A to Z, put each attribute on its own line, and choose how attributes appear in JSON. The tool remembers your choices.
Common XML errors
Tags closed in the wrong order
In XML, the last tag opened must be the first one closed. Names are case-sensitive, so </Title> does not close <title>.
<book><title>Midnight Rain</book></title><book><title>Midnight Rain</title></book>A bare ampersand
An & starts an entity in XML. To write the character itself, use &. The same goes for <, written <.
<company>Ben & Jerry</company><company>Ben & Jerry</company>An attribute without quotes
Every attribute value must be in single or double quotes, and every attribute needs a value.
<price currency=EUR>44.95</price><price currency="EUR">44.95</price>XML
XML (Extensible Markup Language) is a markup language and file format for storing, sending and rebuilding data. It was designed by the W3C and first published as a recommendation in 1998. Unlike HTML, which uses a fixed set of tags for presentation, XML lets you define your own tags to describe the structure and meaning of data.
- The conventional extension for XML files is
.xml. Related formats use their own extensions, such as.xsl,.xsd,.svgand.xhtml. - The MIME type for XML files is
application/xmlortext/xml. XML-based formats may have their own, such asimage/svg+xmlfor SVG.
XML vs HTML
XML and HTML both use tags and attributes in angle brackets, but they serve different purposes. HTML is made for showing content in web browsers, with a fixed set of tags. XML is made for carrying and describing data, with tags you define. XML has strict rules: elements must be nested and closed correctly, attribute values must be quoted, and tag names are case-sensitive.
Key features
- Self-describing. Meaningful tag names and attributes describe the structure, so documents are readable without separate documentation.
- Extensible. There are no predefined tags. You create your own elements and attributes for your field.
- Platform-independent. XML is plain text that any programming language on any operating system can process.
- Can be validated. XML documents can be checked against schemas (DTD, XSD, RELAX NG) to make sure they follow a defined structure.
Common use cases
- Configuration files. Many frameworks use XML for configuration, including Maven (
pom.xml), Spring, Android layouts and ASP.NET (web.config). - Data exchange. XML is widely used to exchange data between systems, especially in enterprise environments with SOAP web services.
- Document markup. Formats like XHTML, DocBook and SVG are XML-based languages for documents and graphics.
- Web feeds. RSS and Atom feeds use XML to share content across websites and applications.
- Office documents. Modern office formats (OOXML and ODF) use XML inside to store documents, spreadsheets and presentations.
XML standards and technologies
The XML family includes several related W3C standards. Namespaces let several XML vocabularies live in one document. XPath is a query language for selecting nodes in XML documents. XSLT transforms XML documents into other formats such as HTML or plain text. XML Schema (XSD) defines the structure, content and data types of XML documents for validation.
Other XML resources
- W3C XML 1.0 SpecificationThe official W3C specification for Extensible Markup Language (XML) 1.0.
- Namespaces in XMLThe W3C recommendation for using namespaces in XML documents.
- XML on MDNThe Mozilla Developer Network guide to XML and related technologies.
- W3Schools XML TutorialA beginner-friendly tutorial on XML syntax, validation, and usage.
- XSLT 3.0 SpecificationThe W3C specification for XSL Transformations, which transform XML documents.
- XML Schema (XSD)The W3C XML Schema language for describing the structure of XML documents.
XML FAQ
Does the formatter keep XML declarations and processing instructions?
Yes. The formatter keeps <?xml ...?> declarations, other processing instructions, comments and CDATA sections. It only changes the whitespace and indentation of your document.
Does it handle namespaces correctly?
Yes. Namespace declarations (xmlns), prefixed elements such as <media:thumbnail>, and default namespaces all work. When attribute sorting is on, xmlns declarations always come first.
Can I format SVG, RSS, SOAP, and other XML-based formats?
Yes. The tool works with any well-formed XML, including SVG graphics, RSS and Atom feeds, SOAP envelopes, Maven POM files, Android layouts, Spring configuration, XSLT stylesheets and sitemaps.
What is the difference between XML and HTML?
XML is strict and extensible: you define your own tags, every tag must be closed, names are case-sensitive and attribute values must be quoted. HTML is more lenient, has a fixed set of tags, and browsers show it even with errors. XHTML is a stricter variant of HTML that follows the XML rules.
What does well-formed mean?
Well-formed XML follows the basic syntax rules of XML: one root element, every tag closed in the right order, quoted attribute values, no repeated attributes, and & and < written as entities in text. This tool checks that. Checking against a schema (DTD or XSD), which is called validation, is a separate step.