Debian Codegraph @

xmlpretty

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/perl
2
3 use strict;
4 use XML::Handler::YAWriter;
5 use XML::Parser::PerlSAX;
6 use IO::File;
7
8 my $options;
9 $options->{Output} = new IO::File(">-");
10
11 while ($ARGV[0] =~ "^--") {
12 my $opt=shift @ARGV;
13 $opt =~ s/^--//;
14 $options->{Pretty}{$opt}=1;
15 }
16
17 my $file = new IO::File( $#ARGV >=0 ? "<".$ARGV[0] : "<-" );
18
19 my $ya = new XML::Handler::YAWriter( $options );
20 my $perlsax = new XML::Parser::PerlSAX(
21 'Handler' => $ya,
22 'Source' => { ByteStream => $file }
23 );
24
25 $perlsax->parse();
26
27 0;
28
29 =head1 NAME
30
31 xmlpretty - XML pretty printer
32
33 =head1 SYNOPSIS
34
35 xmlpretty [--options] [filename]
36
37 =head1 DESCRIPTION
38
39 B<xmlpretty> is the commandline interface to XML::Handler::YAWriter,
40 acting as a tool to add and remove pretty printing to XML files.
41
42 B<xmlpretty> has several methods to add human readablitiy.
43
44 If you want to add readablity without adding so-called I<ignorable
45 whitespace>, use it in the following way :
46
47 $ xmlpretty --AddHiddenNewline \
48 --AddHiddenAttrTab \
49 --CatchEmptyElement \
50 uglyfile.xml > prettyfile.xml
51
52 If you do B<not> want to process the file further, but only want it human
53 readable, add visible whitespace to the file as follows :
54
55 $ xmlpretty --PrettyWhiteNewline \
56 --PrettyWhiteIndent \
57 --CatchEmptyElement \
58 uglyfile.xml > prettyfile.xml
59
60 You may use YAWriter to clean whitespace from XML documents.
61 This may work in 99% of the cases where you want to get rid of
62 ignorable whitespace caused by the various forms of pretty
63 printing.
64
65 $ xmlpretty --NoWhiteSpace \
66 --NoComments \
67 --AddHiddenNewline \
68 --AddHiddenAttrTab \
69 --CatchEmptyElement \
70 prettyfile.xml > cleanfile.xml
71
72 =head2 Options
73
74 Options are given in a gnu like --option idiom.
75
76 =over
77
78 =item AddHiddenNewline boolean
79
80 Add hidden newline before ">"
81
82 =item AddHiddenAttrTab boolean
83
84 Add hidden tabulation for attributes
85
86 =item CatchEmptyElement boolean
87
88 Catch empty Elements, apply "/>" compression
89
90 =item CatchWhiteSpace boolean
91
92 Catch whitespace with comments
93
94 =item IsSGML boolean
95
96 This option will cause start_document, processing_instruction and doctype_decl
97 to appear as SGML. The SGML is still well-formed of course, if your SAX events
98 are well-formed.
99
100 =item NoComments boolean
101
102 Supress Comments
103
104 =item NoDTD boolean
105
106 Supress DTD
107
108 =item NoPI boolean
109
110 Supress Processing Instructions
111
112 =item NoProlog boolean
113
114 Supress <?xml ... ?> Prolog
115
116 =item NoWhiteSpace boolean
117
118 Supress WhiteSpace to clean documents from prior pretty printing.
119
120 =item PrettyWhiteIndent boolean
121
122 Add visible indent before any eventstring
123
124 =item PrettyWhiteNewline boolean
125
126 Add visible newlines before any eventstring
127
128 =item SAX1 boolean (not yet implemented)
129
130 Output only SAX1 compilant eventstrings
131
132 =back
133
134 =head2 Bugs:
135
136 Automatic recoding between 8bit and 16bit does not yet work correctly !
137
138 I have Perl-5.6 at home and here I can specify "use utf8;" in the right
139 places to make recoding work. But I dislike saying "use 5.00555;" because
140 many systems run 5.00503.
141
142 =head1 AUTHOR
143
144 Michael Koehne, [email protected]
145
146 =head1 Thanks
147
148 "Derksen, Eduard (Enno), CSCIO" <[email protected]> helped me with the Escape
149 hash and gave quite a lot of usefull comments.
150
151 =head1 SEE ALSO
152
153 L<perl> and L<XML::Parser::PerlSAX>
154
155 =cut