Zum Inhalt springen

XML-Formatter

XML hübsch formatieren oder minifizieren mit sauberer Einrückung - im Browser.

Läuft in deinem Browser

XML einfügen, saubere eingerückte Version erhalten - oder minifizieren auf eine Zeile. Self-closing, CDATA und Kommentare bleiben erhalten.

So funktioniert's

  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.

Was ist das?

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.

Wann verwenden

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.

Häufige Fehler

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.

Mehr in dieser Kategorie