xmltoolskit.org
XML utilities, in the browser
Say hi →

XML Sort

updated 20 August 2026 · by name, child or attribute · numeric aware

Put an XML document into a predictable order: sort sibling elements by tag name, by the text of a chosen child, or by an attribute value — ascending or descending, text or numeric, one level or the whole tree.

sort
Drop a .xml file here, or
ready

XML Sort

Sorting reorders sibling elements only — it never moves an element to a different parent, and it never changes text, attributes, or values. Use it to make two exports comparable, to alphabetise a configuration, or to rank records by a field before eyeballing them.

How to use it

  1. Paste your XML, or drop a file on the left pane.
  2. Choose what to sort by. For child element value or attribute value, type the child or attribute name in the next box.
  3. Tick numeric when the sort key is a number — otherwise 10 sorts before 9.
  4. Copy or download the sorted document.

The four sort keys

When the chosen child or attribute is missing from an element, its key is empty, which sorts first ascending and last descending — so incomplete records cluster together rather than scattering.

Numeric ordering and case

Text ordering compares character by character, which is why 10 lands before 9. Tick numeric and values are compared as numbers, with anything unparseable sorted after the numbers. Ignore case folds case for the comparison only — names themselves are never rewritten.

Scope, and why sorting is safe

The whole tree is sorted by default: every element's children are ordered, at every depth. Restrict it to the root's children when only the top-level order matters and the contents are deliberately arranged.

In XML, sibling order is significant in principle — a schema can require a specific sequence, and xs:sequence does. Sorting a document that must match such a schema will break validation. For configuration files, logs, and data exports, order is almost always incidental and sorting is exactly what makes them comparable.

FAQ

Does sorting change my data?

Only the order of sibling elements. Text, attributes, comments and CDATA are all preserved; nothing is renamed and nothing moves between parents. Whitespace is normalised because the document is re-indented on the way out.

Why did nothing move?

Either the document is already in that order, or the sort key resolves to the same value for every sibling — a common surprise when the child or attribute name is misspelled. The status line reports how many elements had their children reordered.

Can I sort attributes as well?

Yes, tick sort attributes too and each element's attributes are written in alphabetical order. Attribute order is explicitly insignificant in XML, so this is always safe — and it makes diffs much quieter.

Will the sorted file still validate?

If the schema uses xs:sequence, possibly not: a sequence fixes the order of child elements. Documents using xs:all, or with no schema at all, are unaffected.

Is anything uploaded?

No. Sorting runs in your browser.

Related tools

Privacy

100% client-side. The document is parsed, reordered and re-serialised in the page. See the privacy policy.