XML Sort
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.
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
- Paste your XML, or drop a file on the left pane.
- Choose what to sort by. For child element value or attribute value, type the child or attribute name in the next box.
- Tick numeric when the sort key is a number — otherwise
10sorts before9. - Copy or download the sorted document.
The four sort keys
- Element name — alphabetise siblings by tag name. The right choice for configuration files and for making two documents diffable.
- Child element value — rank records by a field: type
priceand each<product>is ordered by its<price>child. - Attribute value — the same idea for data held in attributes: type
idto sort byid="…". - Element text — the element's entire text content, useful for simple lists of values.
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
- XML Diff — sort both sides first and the diff shows real changes
- XML Formatter — indentation and minification
- XML Stats — find out which elements repeat before sorting
- Namespace Remover — simplify names before sorting by them
- Schema Validator — check a sorted document still validates
Privacy
100% client-side. The document is parsed, reordered and re-serialised in the page. See the privacy policy.