XML Sorter

Reorder sibling elements alphabetically by tag name, attribute value or text, so two versions of a document can finally be compared.

XML
Sorted XML
Runs locally in your browser

About the XML Sorter

Two config files can describe exactly the same thing and still produce a hundred line diff, purely because someone appended a block at the bottom instead of in the middle. Sorting both files the same way removes that noise. This tool reorders sibling elements wherever it safely can and leaves everything else alone, so the result is still valid and still means the same thing.

Safely is the important word. A node whose children are mixed with real text, such as a paragraph with inline markup inside it, is never reordered, because moving those elements would rewrite the sentence. Only nodes whose element children sit among whitespace are touched. Sorting is stable, so elements that compare equal keep their original order, and comparison uses a natural ordering by default: item2 lands before item10 rather than after it, which is almost always what you meant.

Sort by attribute value when your records carry a key, and type that attribute name in the box beside it. Child element text works the same way for documents that put the key in a nested tag rather than an attribute. Sorting attributes is off by default, since attribute order carries no meaning in XML but changing it makes for a noisier first diff. The status line reports how many parent nodes were actually reordered. Once both files are sorted, XML Diff shows what genuinely changed.

How to use

  1. Paste the XML document you want to reorder.
  2. Choose what to sort by. For attribute or child text sorting, type the name in the box beside the menu.
  3. Pick Every level to sort the whole tree, or Root children only to reorder the top blocks and leave their contents alone.
  4. Turn on Sort attributes too when you want a fully canonical form for comparison.
  5. Copy or download the sorted document.

Common questions

Will sorting change what my document means?
For record style XML no, but order can be significant in some schemas, so check before you commit a sorted file to a system that reads sequences.
Why were some elements left alone?
Nodes that mix elements with real text are skipped on purpose, because reordering them would scramble the text around them.
Are comments preserved?
Comments survive, though a comment that sat between two elements ends up above the sorted group rather than glued to its old neighbour.
What does natural number order do?
It compares digit runs as numbers, so id 9 sorts before id 10 instead of after it as plain text comparison would.