equal
deleted
inserted
replaced
15 |
15 |
16 use strict; |
16 use strict; |
17 |
17 |
18 use XML::Parser; |
18 use XML::Parser; |
19 use Getopt::Long; |
19 use Getopt::Long; |
|
20 |
|
21 use FindBin; |
|
22 use lib "$FindBin::Bin/lib"; |
|
23 |
|
24 use XML::Printer; |
20 |
25 |
21 # Read option arguments |
26 # Read option arguments |
22 my $howtoString; |
27 my $howtoString; |
23 my $xslLink; |
28 my $xslLink; |
24 my $help; |
29 my $help; |
59 my $outTree = mergeMultipleTrees($mergeTags, @ARGV); |
64 my $outTree = mergeMultipleTrees($mergeTags, @ARGV); |
60 |
65 |
61 # Output total tree |
66 # Output total tree |
62 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
67 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
63 print "<?xml-stylesheet type=\"text/xsl\" href=\"$xslLink\"?>\n" if $xslLink; |
68 print "<?xml-stylesheet type=\"text/xsl\" href=\"$xslLink\"?>\n" if $xslLink; |
64 printTree($outTree->[0]); |
69 XML::Printer::printTree($outTree->[0]); |
65 print "\n"; |
70 print "\n"; |
66 |
71 |
67 exit(0); |
72 exit(0); |
68 |
73 |
69 sub mergeMultipleTrees |
74 sub mergeMultipleTrees |
145 } |
150 } |
146 |
151 |
147 return undef; |
152 return undef; |
148 } |
153 } |
149 |
154 |
150 sub printTree |
|
151 { |
|
152 my $tree = shift or die; |
|
153 die unless ref $tree; |
|
154 |
155 |
155 my $tagName = ref $tree; |
|
156 $tagName =~ s{^main::}{}; |
|
157 if ($tagName eq "Characters") |
|
158 { |
|
159 print $tree->{Text}; |
|
160 return; |
|
161 } |
|
162 |
|
163 print "<$tagName"; |
|
164 |
|
165 foreach my $attr ( |
|
166 sort |
|
167 grep { |
|
168 ! ref $tree->{$_} |
|
169 } |
|
170 keys %$tree) |
|
171 { |
|
172 print " $attr=\"$tree->{$attr}\""; |
|
173 } |
|
174 |
|
175 my $children = $tree->{Kids}; |
|
176 if (scalar @$children) |
|
177 { |
|
178 print ">"; |
|
179 foreach my $child (@$children) |
|
180 { |
|
181 printTree($child); |
|
182 } |
|
183 print "</$tagName"; |
|
184 } |
|
185 else |
|
186 { |
|
187 print "/" |
|
188 } |
|
189 |
|
190 print ">"; |
|
191 } |
|
192 |
|
193 |
|