initial import
[vym] / scripts / niceXML
1 #!/usr/bin/perl 
2 #
3 # Hack to make single-line XML file  easier to read by using indention
4 #
5 # (c) Uwe Drechsel
6 #
7 # License: GPL 
8
9 my $filename =shift;
10 my $s;
11 open (INFILE, "<$filename") ||
12         die "Could not read $filename.";
13 $s=join("\n",<INFILE>);
14
15 $s=~s/>/>\n/gm;
16
17 my @lines=split ("\n",$s);
18 my $i=0;
19 my $is="";
20
21 foreach (@lines)
22 {
23         if (!/<.*?\/>/)
24         {
25                 if (/<\//)
26                 {
27                         # Closing tag
28                         $i--;
29                         if ($i<0) {$i=0};
30                         $is=indent($i);
31                         print "$is$_\n";
32                 } else
33                 {
34                         if (/<(?!\?)/)  # ignore <? ... ?>
35                         {
36                                 # Opening tag
37                                 print "$is$_\n";
38                                 $i++;
39                                 $is=indent($i);
40                         } else 
41                         { 
42                                 # empty lines etc
43                                 print "$is$_\n"; 
44                         }
45                 }
46         } else 
47         { 
48                 # Ignor single tags <../>
49                 print "$is$_\n"; 
50         }
51 }
52 print "\n";
53 exit;
54
55 sub indent()
56 {
57         my $size=shift;
58         my $s="";
59         for ($i=0; $i<$size; $i++)
60         {
61                 $s=$s."  ";
62         }
63         return $s;
64 }