liminfo

XML Formatter

Free web tool: XML Formatter

About XML Formatter

The XML Formatter is a free, browser-based tool that lets you format, minify, validate, and query XML documents instantly. Paste raw or minified XML and click Format to get a properly indented, human-readable structure with full syntax highlighting — tags in blue, attributes in orange, values in green, and text content clearly distinguished. The formatter handles nested elements, self-closing tags, processing instructions, CDATA sections, and inline content.

The XML Validation feature uses the browser's native DOMParser with the application/xml MIME type to detect well-formedness errors. When validation fails, the tool reports the exact error message along with line and column numbers, making it easy to locate and fix structural problems. When validation succeeds, it displays the root element name and total element count for a quick structural overview.

The XPath Query feature lets you run XPath expressions against your XML document using the browser's native document.evaluate() API. Enter any XPath expression — from simple element selectors like //item to complex predicates like //node[@attr="value"] — and instantly see all matching nodes serialized as formatted XML with syntax highlighting. The result count is always displayed, and individual nodes can be copied independently.

All processing runs entirely in your browser using JavaScript. No XML content is ever sent to a server, logged, or stored. The tool supports arbitrarily large documents limited only by browser memory, works seamlessly on desktop and mobile, and includes one-click copy of results. Dark mode is fully supported.

Key Features

  • Format XML with two-space indentation and syntax highlighting — tags, attributes, and values in distinct colors
  • Minify XML by stripping all inter-tag whitespace for compact production payloads
  • Validate XML well-formedness with detailed error reporting including line and column numbers
  • Run XPath queries against XML documents using the native browser XPath engine (document.evaluate)
  • XPath results displayed as formatted XML with node count and per-node copy buttons
  • Quick XPath expression examples for common patterns like //element, /root/*, //node[@attr]
  • Syntax highlighting: blue tags, orange attributes, green values, purple entities, gray comments
  • One-click copy for formatted output, validation results, and individual XPath matches
  • Tabbed interface for clean separation of Format/Minify, Validation, and XPath features
  • 100% client-side processing — XML data never leaves your browser or device

Frequently Asked Questions

What is the difference between Format and Minify?

Format adds proper indentation and line breaks to make XML human-readable, ideal for debugging or editing. Minify removes all whitespace between tags to produce the smallest possible output, ideal for network transmission, API payloads, or embedded configurations where file size matters.

What does the Validate button check?

Validate uses the browser's built-in DOMParser to parse your XML as application/xml. If the document is not well-formed — for example, unclosed tags, mismatched element names, illegal characters, or missing root element — the parser returns an error with line and column information. On success, it shows the root element name and total element count.

How does the XPath Query feature work?

The XPath Query feature parses your XML using DOMParser and then executes your XPath expression using the native document.evaluate() API. It returns all matching nodes as an ordered snapshot. Element nodes are serialized back to formatted XML with syntax highlighting. Attribute nodes show name="value" pairs, and text nodes show their text content directly.

What XPath expressions are supported?

Any valid XPath 1.0 expression is supported, as it uses the browser's native XPath engine. This includes element selectors (//item), attribute selectors (//item[@id]), predicates (//item[position()=1]), axis navigation (ancestor::div), and functions (count(), string(), contains(), starts-with()). XPath 2.0+ features are not supported by browser engines.

Can I format very large XML files?

Yes. The formatter processes XML entirely in memory using JavaScript string operations. There is no file-size limit imposed by the tool itself. Performance depends on your browser and device; files up to several megabytes typically process in milliseconds on modern hardware.

How does the syntax highlighting work?

The syntax highlighter uses regex-based parsing to identify XML constructs: tags and brackets appear in blue, attribute names in orange, attribute values in green, entity references in purple, comments in gray, CDATA sections in amber, and text content in the default text color. Line numbers are displayed alongside the output.

Does the formatter handle XML namespaces?

Yes. The formatter preserves all attributes, namespace declarations (xmlns), and namespace-prefixed elements exactly as entered. XPath queries also work with namespaced documents, though namespace-prefixed expressions may require a custom namespace resolver for complex cases.

Why does validation pass but my app still rejects the XML?

This tool checks XML well-formedness only — that all tags are properly opened, closed, and nested. It does not validate against an XSD schema or DTD. Schema validation (correct element names, attribute types, value constraints) requires a separate schema-aware validator.

Is my XML data private?

Yes. All formatting, validation, and XPath querying happen entirely within your browser tab. No data is transmitted to any server. The tool has no backend, no analytics on input content, and no clipboard access beyond the explicit Copy button actions.