#!/bin/perl # Copyright (c) 2008 by Emin Gabrielyan, Switzernet if(@ARGV!=1) { print "arguments: \n"; exit; } $fname=$ARGV[0]; if(!open fh,$fname) { print "cannot open file $fname\n"; exit; } @lines=; close fh; $"=""; $_="@lines"; s/[\r\n]//sg; s/<[^\/]/\n$&/sg; while(s/(<\/[^>]+>)(<\/[^>]+>)/$1\n$2/sg){} @tags=split/\n/; foreach $_ (@tags) { $indent=" "x$i; if(/^<[\w][^<]*$/) { $i++; } elsif(/^<\//) { $i--; $indent=" "x$i; } $out.="$indent$_\n"; } #$fname=~s/^.*\/(?!.*\/)//; #uncomment for saving in the current directory $fname=~s/\.xml$//; $fname.=".indent.xml"; $_=$out; open out,">$fname"; s/\n/\r\n/sg; print out; close out;