Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some enormous XML-based configuration files, with 125000 lines in them. The problem is that they are auto-generated by the system I use, and "child" tags are in a random order within their respective parent tag. This means that a diff comparison is impossible.

I want to recursively sort all tags within a parent tag by the value in name="". Some parent tags only appear once and don't have a name="" parameter; these should be sorted by the tag name itself.

Once the files are sorted like this, they can be compared quite easily using normal tools. We are currently using ExamXML which can match unsorted XML files, but it fails because the files are too big.

Is there an application that can do this? (Windows much preferred; Linux only as a last resort)

I do not want to dive into development or XSLT jobs. I am thinking that someone must have made a simple sorting tool like this already - I just can't find it using Google.

With help from this site, I created a small package that I want to share:

Update: Follow-up question here.

share|improve this question
up vote 4 down vote accepted

I know you don't want to dive into XSLT, but it's by far the easiest way of doing it. All it takes is:

<xsl:stylesheet version="2.0" xmlns:xsl="">
<xsl:template match="*">
    <xsl:copy-of select="@*"/>
      <xsl:sort select="(@name, name())[1]"/>
share|improve this answer
I have no understanding of XSLT, but this looks like it automatically runs through the tag names so I don't have to enumerate them. That is a BIG advantage over other XSLT-based solutions I've seen in my searches! Given your example, can I just take this and run it, or how would I need to adapt it? How do I actually "run" an XSLT? In a browser? (XML noob speaking...) – Torben Gundtofte-Bruun Nov 8 '11 at 19:07
How to run: I found this somewhat related question but I don't really understand the answers. – Torben Gundtofte-Bruun Nov 8 '11 at 19:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.