Aller au contenu

Formateur XML

Mettez en forme ou compactez du XML avec une indentation propre - dans votre navigateur.

Fonctionne dans votre navigateur

Collez du XML, obtenez une version indentée propre - ou minifiez pour revenir à une seule ligne. Self-closing, CDATA et commentaires préservés. Le parseur tourne dans votre navigateur.

Comment l'utiliser

  1. Paste your XML

    Any well-formed XML, with or without an XML declaration.

  2. Pick pretty-print or minify

    Pretty-print uses 2 spaces by default; switch to 4 spaces or tabs if your codebase prefers.

  3. Copy the result

    Output appears in the right pane. Hit Copy to grab it.

Qu'est-ce que c'est ?

An XML formatter rewrites a string of XML in a canonical form - either indented for reading or stripped to a single line for storage / transport. The structural facts (elements, attributes, text, CDATA, comments) are preserved; only whitespace between nodes changes. Pretty-printing is the most common use; minifying is occasionally needed for shaving bytes off a payload.

Quand l'utiliser

Reading a one-line XML response from an API. Comparing two XML files in a diff tool that doesn't ignore whitespace. Pasting an SVG into source control after a graphics tool wrote it as a single line. Stripping pretty-printed XML before embedding in an attribute or generating a small QR code.

Erreurs courantes

Treating the result as canonical XML for signature purposes - real XML canonicalisation (c14n) is a separate spec and this tool doesn't implement it. Assuming attribute order is preserved across parser implementations (it is here, but XML technically doesn't guarantee it). And running the minifier on XML that contains significant whitespace in <pre>-like content - any whitespace-sensitive content needs CDATA or escaped runs.

FAQ

Does it validate the XML?
It uses the browser's DOMParser, which surfaces malformed XML as a parser error. Validation against a schema (XSD, DTD, RelaxNG) is out of scope.
What about XML namespaces?
Namespaces are preserved on the tags that declare or use them. The formatter doesn't re-prefix or normalise them.

Plus dans cette catégorie