Skip to content
ZeroServer.tools

XML Sorter

Recursively sort sibling elements and attributes alphabetically, then re-serialize the document.

Drop an .xml file or click to browseAll processing stays local in your browser.
Sorted Output

How XML sorting works

This tool parses your XML into a tree using a lightweight parser written from scratch (no browser DOM APIs), then walks the tree recursively: at every element, consecutive runs of sibling elements are reordered alphabetically by tag name, and each element's attributes are sorted alphabetically by attribute name. Text content, comments, and CDATA sections are left exactly where they are relative to the elements around them, so mixed content is never scrambled — only same-level element runs get reordered.

Sorting is useful for diffing two XML files that differ only in element order, normalizing config files or RSS/Atom feeds for version control, or making generated XML deterministic and easier to review. Toggle attribute sorting off if you only want elements reordered, and toggle case-sensitive sorting on if you need strict ASCII ordering (uppercase before lowercase) instead of natural alphabetical order. Everything runs locally in your browser — nothing is ever uploaded.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Making two XML documents comparable when their elements are in different orders.
  • Producing a canonical form before diffing two config files.
  • Tidying a generated document whose element order is arbitrary.
  • Sorting attributes so a diff does not show reordering as change.
  • Checking whether two exports contain the same data in a different sequence.

Frequently Asked Questions

What can be sorted?
Child elements, by tag name or by the value of an attribute or child element. Attributes on a single element can also be ordered, which is useful for producing a stable diff between generated files.
Is reordering XML safe?
It depends on the schema. Order is insignificant in many configuration formats and significant in document formats and anywhere a sequence models a list. A schema using `xs:sequence` requires the declared order.
Does attribute order matter?
Not to any conformant parser — the XML specification says attribute order is not significant. It matters only to text diffs, which is exactly why sorting them makes generated files comparable.
What happens to comments and whitespace?
Comments move with the elements they precede where the structure allows. Insignificant whitespace between elements is not preserved through a parse-and-serialise cycle, so expect reformatting.
Why is the sort case-sensitive?
Because XML itself is case-sensitive — `<Item>` and `<item>` are genuinely different elements. Case-insensitive sorting would interleave two distinct element types as if they were one.
Will it fix invalid XML?
No — it must parse the document first, so an unclosed tag or an unescaped `&` is reported rather than repaired. Unlike HTML, XML parsers are required to reject malformed input outright.

Common errors and gotchas

  • Sorting a document where order is significant, which changes the data rather than tidying it.
  • Assuming attribute order matters. It does not in XML, which is why sorting them is safe and sorting elements often is not.
  • Losing comments or processing instructions if the serialiser drops them.
  • Sorting through a CDATA section or mixed content, which can reflow text meaningfully.
  • Expecting the result to validate against the same schema, when a sequence-based schema will now reject it.

Related Formatters & Validators tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate