XML Formatter & Pretty Printer
Text ToolsPaste your XML document and click Format to get a nicely indented output with syntax highlighting.
Result:
XML Format Guide
XML Syntax Reference
XML (Extensible Markup Language) uses a tree structure of nested elements. Every XML document must have exactly one root element, and all tags must be properly closed.
| Construct | Syntax |
|---|---|
| Element | <tag>content</tag> |
| Attribute | <tag attr="value"> |
| Self-closing | <tag /> |
| Comment | <!-- text --> |
| CDATA | <![CDATA[ text ]]> |
| Declaration | <?xml version="1.0"?> |
Common Use Cases
XML formatting is useful in many development and data exchange scenarios.
- API debugging — Inspect and format SOAP/REST XML responses for easier analysis.
- Configuration files — Format Maven pom.xml, Spring beans, and other config files for readability.
- Data interchange — Verify XML exports from databases, spreadsheets, or enterprise systems.
- SVG editing — Pretty-print SVG graphics files to understand and modify their structure.
Tips
- XML is case-sensitive — <Name> and <name> are different elements.
- Attribute values must always be quoted with single or double quotes.
- Special characters like <, >, and & must be escaped as <, >, and & in text content.
- Use CDATA sections to include blocks of text that contain many special characters without escaping.
Glossary
- XML (Extensible Markup Language)
- A markup language for encoding documents in a human-readable and machine-readable format. XML is a W3C standard widely used for data interchange between systems, configuration files, and document formats like SVG and XHTML.
- Well-formed XML
- An XML document that follows all syntax rules: it has exactly one root element, all tags are properly nested and closed, attribute values are quoted, and element names are case-sensitive. A well-formed document can be parsed by any XML parser.
- XML Schema (XSD)
- A W3C standard for defining the structure, content, and data types of XML documents. Unlike DTD, XSD itself is written in XML and supports data types, namespaces, and complex type definitions.
- Namespace
- A mechanism to avoid element name conflicts by qualifying names with a URI. Declared using the xmlns attribute (e.g., xmlns:xsl="http://www.w3.org/1999/XSL/Transform"), namespaces enable combining elements from different vocabularies in a single document.
- XSLT
- Extensible Stylesheet Language Transformations (XSLT) is a language for transforming XML documents into other formats such as HTML, plain text, or different XML structures. It uses template rules to match and process elements.
Frequently Asked Questions
- Q: Is my data safe when using this tool?
- A: Yes. All processing is done entirely in your browser using JavaScript. Your XML data is never sent to any server.
- Q: What is the difference between XML and HTML?
- A: XML is a strict, extensible markup language for data representation, while HTML is designed for displaying web pages. XML requires all tags to be closed and is case-sensitive, whereas HTML is more lenient.
- Q: Can this tool validate XML?
- A: This tool checks for well-formedness (proper nesting and closing of tags). It does not validate against an XML Schema (XSD) or DTD.
- Q: What indentation does the formatter use?
- A: The formatter uses 2-space indentation by default, which is the most common convention for XML documents.