Skip to content

XML formatter and validator

Pretty-print or minify XML and see the line and column where it fails to parse.

Runs in your browser. Nothing you paste is sent to us.

XML

A sample SAML request on one line is filled in. Paste any XML; it is parsed as XML, never as HTML.

Formatted

Result
 
Reformatting changes whitespace, which breaks an XML signature. Send the original bytes, not the formatted copy.
Well-formed means the XML parses. It is not checked against a schema such as SAML’s.

How to use it

  1. Paste the XML.
  2. Pick pretty or minified output, and the indent.
  3. If it does not parse, read the line and column of the first error.
  4. Copy the result.

What to know

The XML is parsed by your browser’s XML parser, never rendered as a page, and printed back with the indent you pick. Text inside elements is kept as it is.

Formatting is for reading. Signed SAML messages must be sent byte for byte as they were signed, so never send a reformatted copy of a signed message.

Well-formed is not the same as valid: the tool checks that the XML parses, not that it matches a schema.

Why format XML

XML that machines write is often one long line. SAML messages, metadata files and many configuration exports arrive that way. Reading them, comparing them or finding one attribute inside them is slow until the elements are on their own lines and indented by depth.

Minifying does the opposite: it removes the whitespace between elements to make a document smaller, for example before Base64-encoding it or putting it in a single-line setting.

Well-formed XML in short

A parser accepts XML only if it is well formed. The main rules:

  • Exactly one root element.
  • Every start tag has a matching end tag, or the element is self-closing like <a/>.
  • Elements nest properly: <a><b></b></a>, never <a><b></a></b>.
  • Attribute values are quoted, and an element has each attribute at most once.
  • < and & in text are written as &lt; and &amp;.
  • Namespace prefixes such as saml: are declared with xmlns:saml="…" on the element or an ancestor.

Well formed is not the same as valid. A valid document also follows a schema, such as the SAML schemas, which define which elements may appear where. This tool checks well-formedness only.

What this tool does

Paste XML and pick Pretty or Minify. The tool parses the text with your browser’s XML parser, never as HTML, and prints it back.

  • Pretty puts each element on its own line, indented by two spaces, four spaces or a tab.
  • Minify removes the whitespace-only text between elements.
  • Text inside an element is kept exactly as it was, so values are never changed.
  • Comments can be kept or dropped. The XML declaration at the top is kept.
  • Badges show the root element, the number of elements and the number of namespaces.

If the XML does not parse, the tool shows the browser’s error with the line and column where parsing stopped.

Before and after
<a><b x="1">text</b><c/></a>

<a>
  <b x="1">text</b>
  <c/>
</a>

Comments, CDATA and processing instructions

Comments are kept by default; turn off Keep comments to drop them. CDATA sections are printed back exactly, since their content is text that must not change. Processing instructions, such as a stylesheet reference, are kept as they were.

What it does not do

It does not validate against a schema, resolve external entities, or fetch anything a document points to. A document type declaration is kept by name, but its internal subset is not printed. It does not sort attributes or rewrite namespace prefixes.

How to use it

  1. Paste the XML.
  2. Pick Pretty or Minify, and for Pretty the indent.
  3. If an error appears, go to the line and column it names and fix the first problem. Later errors often disappear with it.
  4. Copy the result.

Formatting breaks XML signatures

This is the most important caveat for SAML. An XML signature covers the canonical form of the signed element. Canonicalization normalizes some things, such as attribute order and namespace declarations, but whitespace between elements stays part of the signed content.

So once a SAML response, assertion or metadata file is signed, adding or removing line breaks inside the signed element changes its digest and the signature no longer verifies. Format a copy to read it, but always send, store or import the original bytes.

If a signature fails only after someone “cleaned up” a metadata file or a response in an editor, this is usually why.

Use cases

Reading a decoded SAML message

The SAML response decoder and SAML request decoder already print their XML indented. For XML from other places, such as logs or a library’s debug output, paste it here.

Reviewing metadata

Metadata from an identity provider is often minified. Format it to see the endpoints and keys, or use the metadata viewer, which lists them for you.

Comparing two documents

Format both with the same indent, then compare them line by line in a diff tool. Differences in attributes and values stand out once the layout is the same.

Preparing XML for a one-line setting

Some consoles and environment variables take XML on one line. Minify it here first, then check that it still parses. Keep in mind that minifying a signed document breaks its signature, just like formatting does.

Finding why a file will not import

When an importer says a file is invalid, check well-formedness here first. If it parses, the problem is in the content, such as a wrong namespace or a missing required element.

Common parse errors

ErrorUsual cause
Extra content at the end of the documentMore than one root element, or text after the root
Opening and ending tag mismatchTags closed in the wrong order, or a typo in a tag name
Namespace prefix is not definedA prefix such as saml: used without its xmlns:saml declaration
EntityRef: expecting ;A bare & in text or in an attribute value
Attribute redefinedThe same attribute twice on one element
Start tag expectedEmpty input, or text that is not XML, such as Base64

The exact wording depends on your browser. Chrome, Edge, Firefox and Safari all report the position.

XML and security

XML parsers have a history of security problems: external entities that read local files, entity expansion that uses all memory, and in SAML, signature wrapping. Browsers’ XML parsers do not load external entities, and this tool never renders the XML as a page, so pasting a document here is safe.

In your own services, parse SAML with a library that disables document type declarations and external entities, and verifies signatures on exactly the element it then reads.

Best practices

  • Keep the original bytes of anything signed; format only copies.
  • Use UTF-8 and say so in the XML declaration.
  • Keep namespace prefixes consistent across your own documents to make diffs readable.
  • Do not hand-edit generated metadata; regenerate it.

Namespaces in SAML documents

SAML documents mix several vocabularies, and XML namespaces keep them apart. The prefix before the colon is only a local nickname; what counts is the namespace URI it is bound to with xmlns:.

Usual prefixNamespace URIUsed for
samlpurn:oasis:names:tc:SAML:2.0:protocolRequests and responses
samlurn:oasis:names:tc:SAML:2.0:assertionAssertions, issuers, attributes
mdurn:oasis:names:tc:SAML:2.0:metadataMetadata
dshttp://www.w3.org/2000/09/xmldsig#Signatures and key info
xenchttp://www.w3.org/2001/04/xmlenc#Encrypted data

Two documents can use different prefixes, or none, for the same namespace and mean exactly the same thing. Software must compare namespace URIs, not prefixes. When you compare two formatted documents and only the prefixes differ, the content is the same.

Encoding, line endings and the declaration

The XML declaration, <?xml version="1.0" encoding="UTF-8"?>, is optional for UTF-8 documents, which is what SAML uses. The tool keeps it when it is there and does not add one when it is not.

XML parsers normalize line endings to a single line feed, so a document saved on Windows and one saved on Linux read the same. A byte order mark at the start is allowed for UTF-8 but some older tools choke on it; the tool ignores it on input.

Questions

Frequently asked questions

How do I pretty-print XML?

Paste it into the tool and pick Pretty. Each element goes on its own line, indented by its depth, and text values stay as they were.

Why does formatting break my SAML signature?

Whitespace inside the signed element is part of what was signed. Adding indentation changes the digest, so the signature check fails. Send the original, unformatted bytes.

What is the difference between well-formed and valid XML?

Well-formed XML follows the syntax rules and parses. Valid XML also matches a schema or DTD. This tool checks well-formedness.

What does "Extra content at the end of the document" mean?

The XML has more than one root element, or text after the root. Wrap everything in one element, or remove what follows the root.

What does "Namespace prefix is not defined" mean?

An element or attribute uses a prefix such as saml: or ds: without an xmlns declaration for it. Add the declaration, often on the root element.

Is it safe to paste XML into this formatter?

Yes. It runs in your browser, sends nothing, does not load external entities and never renders the XML as a page.

Does minifying XML change its meaning?

Removing whitespace between elements does not change data in most documents. It does change signed content. In mixed content, where text and elements are interleaved, a space between two elements can matter, so check such documents after minifying.

Do namespace prefixes matter in XML?

No. Only the namespace URI a prefix is bound to matters. saml:Assertion and a:Assertion are the same element if both prefixes point to the SAML assertion namespace.

How do I find where my XML is broken?

Paste it into the formatter. If it does not parse, the error names the line and column where the parser stopped. The real mistake is at or just before that point.

Can I format SAML metadata with this tool?

Yes, for reading. Keep the original file for importing, because formatting breaks a metadata signature.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.