XML formatter
This XML formatter takes the text you paste below, indents the elements cleanly, can minify everything to one line and shows line and column when something is wrong. Your data stays in the browser.
Source: W3C – Extensible Markup Language (XML) 1.0: Well-Formed XML Documents. Updated: .
How it is calculated
Formatting XML means putting each element on its own line and indenting by level. <a><b>1</b></a> becomes a readable tree with <b> one level below <a>.
What the formatter does
It splits the text into declaration, comments, CDATA, DOCTYPE, tags and text, checks the order of the tags and rebuilds the document with the chosen indentation. Elements that contain only text stay on one line. Minifying removes all whitespace between the tags and, if you like, the comments too.
Finding errors
- Missing or wrongly nested end tag: the tool gives line and column.
- More than one root element, or text outside the root.
- Unclosed tags, comments and CDATA sections.
Element and attribute names, unquoted attributes, duplicate attributes and a bare “&” are checked too. DTD and schema rules are not checked. Everything is processed entirely in the browser.
Tree view, XPath and JSON
- Tree view: every element can be expanded and collapsed; the number after the tag is the count of child nodes. Large documents stay responsive because children are only drawn when you expand them.
- XPath: in the sample, //book[@id=2]/title returns the element <title>Second book</title>, count(//book) gives 2 and //price/@currency lists both currencies. A subset of XPath 1.0 is supported, without long-form axes and arithmetic.
- XML to JSON: attributes become “@name”, repeated elements become arrays. Values stay strings; no number type is guessed.
- Files: open or drop a file, copy or download the result. Files up to 50 MB are read; from 300,000 characters the content stays outside the text field. With very large files the browser may pause briefly.
Security: DOCTYPE and entities
The formatter reads XML with its own tokenizer and does not use the browser’s XML parser. A DOCTYPE stays plain text: external DTDs and entities are never loaded, and self-defined entities are not expanded. Attacks through external entities (XXE) or exploding entities therefore have no effect.
Frequently asked questions
How can I format XML online?
Paste the XML into the field and choose “Format”: the elements are indented with 2 or 4 spaces or a tab. Everything happens in your browser.
How do I find errors in an XML file?
The formatter checks well-formedness and reports the first problem with line and column, for example a wrong or missing end tag.
Is my XML uploaded?
No. Formatting and checking run locally in your browser; nothing is sent to a server.
How do I query XML with XPath?
Open “XPath query” and type an expression, for example //book[@id=2]/title. The matches are listed with their path. A subset of XPath 1.0 is supported.
Can I convert XML to JSON?
Yes, choose “Convert to JSON”. Attributes appear as “@name”, repeated elements as an array, and values stay strings.
Is it safe to open XML files from others?
The formatter never loads anything and does not expand entities from a DOCTYPE, so attacks through external entities (XXE) do not work here.
Sources and legal basis
- W3C – Extensible Markup Language (XML) 1.0: Well-Formed XML Documents
- W3C – XML Path Language (XPath) Version 1.0
- Wikipedia – Extensible Markup Language
As of: · Editorial policy
Related tools
- JSON formatter, validator and minifierValidate JSON against RFC 8259 with the exact line, column and a plain-English explanation. Beautify or minify, sort keys, copy. Runs locally in your browser.
- XML and CSV validator onlineCheck XML for well-formedness and validate CSV against RFC 4180: errors with line and column, auto-detected delimiter, table preview. Runs locally.
- HTML formatterHTML formatter: indent source code to make it readable, or minify it to a single line, with warnings about unclosed tags. Runs locally in your browser.
- YAML to JSON converter (and JSON to YAML)YAML to JSON converter and JSON to YAML following YAML 1.2: lists, anchors, text blocks, comments. Errors show the line number. Runs in your browser, no upload.
- SQL formatter (format SQL online)SQL formatter for readable queries: uppercase keywords, indentation, columns and conditions on separate lines. Also minifies SQL. Runs locally in your browser.
- Sitemap XML generator: build sitemap.xml from your URL listSitemap XML generator without signup: paste URLs, get a valid sitemap.xml per the Sitemaps protocol, check for errors and download it. Runs in your browser.
- What is my IP address?What is my IP? See your public IPv4 or IPv6 address at once, plus approximate location, internet provider and browser details. Free, never stored.
- JSON compareJSON compare: find the differences between two JSON documents with path, old and new value. Key order is ignored. In your browser, no upload.
- JSON to TypeScript converterConvert JSON to TypeScript: generate types, interfaces or JSON Schema from sample data, with optional fields. Runs in your browser, no upload.