XML-Formatierer

So wird es benutzt 3 Schritte
  1. Fügen Sie Ihren Code unter XML-Code einfügen ein.
  2. Drücken Sie XML formatieren.
  3. Kopieren Sie das formatierte Ergebnis.
Formatierte XML-Ausgabe

So funktioniert dieses Werkzeug

Das Dokument wird an den Grenzen zwischen den Tags aufgeteilt und neu eingerückt, wobei beim Betreten eines Elements zwei Leerzeichen hinzukommen und beim Verlassen wegfallen. Daraus entsteht ein lesbarer Baum aus einem Dokument, das als eine einzige ununterbrochene Zeile ankam — so kommt XML meist aus einer API oder einem Export.

Dies ist ein Formatierer und kein Parser: Es rückt erkannte Struktur neu ein und validiert nicht. Ein Dokument mit fehlendem schließenden Tag oder nicht passendem Namen wird genauso bereitwillig eingerückt wie ein korrektes, und der Fehler zeigt sich nur als Einrückung, die in eine Richtung abdriftet, in die sie nicht sollte.

Was es leistet und was nicht

  • Nichts wird validiert: Ein fehlerhaftes Dokument ergibt fehlerhafte Ausgabe statt einer Fehlermeldung. Abdriftende Einrückung ist oft das erste sichtbare Zeichen, dass weiter oben etwas nicht stimmt.
  • Text zwischen Tags übersteht es womöglich nicht sauber: Die Aufteilung erfolgt an Tag-Grenzen, gemischter Inhalt — Text mit Inline-Elementen darin — ist also die Stelle, an der die Ausgabe am wenigsten verlässlich ist.
  • Attribute bleiben exakt, wie sie sind: Reihenfolge, Abstände und Anführungszeichen innerhalb eines Tags bleiben unangetastet. Nur die Einrückung zwischen den Tags ändert sich.
  • Nutzen Sie es zum Lesen, nicht zum Umschreiben: Neu formatiertes XML ist zum Anschauen da. Es wieder in ein System einzuspeisen, dem Leerraum wichtig ist, ist ein Risiko, das dieses Werkzeug für Sie nicht einschätzen kann.

A formatter, not a parser

The [msm_tool slug="xml-formatter"] splits a document at the boundaries between tags and re-indents it, adding two spaces on entering an element and removing them on leaving — which turns a document that arrived as one unbroken line, the way XML usually comes back from an API or an export, into something with a readable tree shape. What it does not do is validate anything along the way: it re-indents structure it recognises rather than checking that structure is actually correct.

Drifting indentation is often the first real warning sign

A document with a missing or mismatched closing tag is re-indented just as willingly as a correct one, with no error reported anywhere — the fault shows up only as indentation that drifts in a direction it should not, rather than returning to where it started once the relevant closing tag appears. That drift is frequently the first visible clue that something upstream produced a malformed document.

Mixed content is where it is least reliable

The split works at tag boundaries, which handles pure element nesting cleanly but is less predictable for mixed content — ordinary text with inline elements sitting inside it. That combination is the case most likely to come out looking different from what a person would have chosen by hand.

Attributes are left exactly as they were

Order, spacing and quoting inside a tag are untouched throughout — only the indentation between tags changes. Anything inside the tag itself is not this tool's concern at all.

Use it to read, not to feed back in

Reformatted output is meant for looking at. Whitespace can be semantically significant depending on the schema a document is validated against, so whether reformatted XML is safe to send back into whatever system produced it is a question this tool has no way to answer on its own behalf.

Where it partly works on HTML, and where it does not

HTML permits tags that never get explicitly closed, which XML's grammar does not allow, so running HTML through this produces the same kind of indentation drift a genuinely malformed XML document would show — not because the HTML is wrong, but because this formatter is reading it as something stricter than it actually is. A formatter built specifically for HTML is the better tool for that job.

Häufig gestellte Fragen

Speziell zum XML-Formatierer. Allgemeinere Fragen zu dieser Kategorie werden auf der Kategorieseite beantwortet.

Nein. Es rückt neu ein; es parst und validiert nicht. Ein kaputtes Dokument wird genauso bereitwillig eingerückt wie ein korrektes.
Meist wegen eines fehlenden oder nicht passenden schließenden Tags. Die Einrückung kehrt erst zurück, wenn ein erkanntes schließendes Tag auftaucht.
Nein. Alles innerhalb eines Tags bleibt unangetastet — nur die Abstände zwischen den Tags ändern sich.
Teilweise. HTML erlaubt nicht geschlossene Tags, die XML nicht zulässt, an ihnen driftet die Einrückung ab. Ein HTML-spezifischer Formatierer ist die bessere Wahl.
Er kann es sein, je nach Schema. Neu formatiertes XML ist sicher zu lesen, sollte aber nicht als sicher zur Weiterverarbeitung gelten.

Abonniere Benachrichtigungen zu neuen Tools, Funktionen und Produktivitätstipps.