XML-Handler-YAWriter-0.23/0040755000076400000620000000000007425335053014312 5ustar kraehestaffXML-Handler-YAWriter-0.23/edifact03.dtd0100644000076400000620000033743607055016013016555 0ustar kraehestaff XML-Handler-YAWriter-0.23/README0100644000076400000620000001745307123542362015177 0ustar kraehestaffNAME XML::Handler::YAWriter - Yet another Perl SAX XML Writer SYNOPSIS use XML::Handler::YAWriter; my $ya = new XML::Handler::YAWriter( %options ); my $perlsax = new XML::Parser::PerlSAX( 'Handler' => $ya ); DESCRIPTION YAWriter implements Yet Another XML::Handler::Writer. The reasons for this one are that I needed a flexible escaping technique, and want some kind of pretty printing. If an instance of YAWriter is created without any options, the default behavior is to produce an array of strings containing the XML in : @{$ya->{Strings}} Options Options are given in the usual 'key' => 'value' idiom. Output IO::File This option tells YAWriter to use an already open file for output, instead of using $ya->{Strings} to store the array of strings. It should be noted that the only thing the object needs to implement is the print method. So anything can be used to receive a stream of strings from YAWriter. AsFile string This option will cause start_document to open named file and end_document to close it. Use the literal dash "-" if you want to print on standard output. AsArray boolean This option will force storage of the XML in $ya->{Strings}, even if the Output option is given. AsString boolean This option will cause end_document to return the complete XML document in a single string. Most SAX drivers return the value of end_document as a result of their parse method. As this may not work with some combinations of SAX drivers and filters, a join of $ya->{Strings} in the controlling method is preferred. Encoding string This will change the default encoding from UTF-8 to anything you like. You should ensure that given data are already in this encoding or provide an Escape hash, to tell YAWriter about the recoding. Escape hash The Escape hash defines substitutions that have to be done to any string, with the exception of the processing_instruction and doctype_decl methods, where I think that escaping of target and data would cause more trouble than necessary. The default value for Escape is $XML::Handler::YAWriter::escape = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', '--' => '--' }; YAWriter will use an evaluated sub to make the recoding based on a given Escape hash reasonably fast. Future versions may use XS to improve this performance bottleneck. Pretty hash Hash of string => boolean tuples, to define kind of prettyprinting. Default to undef. Possible string values: AddHiddenNewline boolean Add hidden newline before ">" AddHiddenAttrTab boolean Add hidden tabulation for attributes CatchEmptyElement boolean Catch empty Elements, apply "/>" compression CatchWhiteSpace boolean Catch whitespace with comments IsSGML boolean This option will cause start_document, processing_instruction and doctype_decl to appear as SGML. The SGML is still well-formed of course, if your SAX events are well-formed. NoComments boolean Supress Comments NoDTD boolean Supress DTD NoPI boolean Supress Processing Instructions NoProlog boolean Supress Prolog NoWhiteSpace boolean Supress WhiteSpace to clean documents from prior pretty printing. PrettyWhiteIndent boolean Add visible indent before any eventstring PrettyWhiteNewline boolean Add visible newlines before any eventstring SAX1 boolean (not yet implemented) Output only SAX1 compliant eventstrings Notes: Correct handling of start_document and end_document is required! The YAWriter Object initialises its structures during start_document and does its cleanup during end_document. If you forget to call start_document, any other method will break during the run. Most likely place is the encode method, trying to eval undef as a subroutine. If you forget to call end_document, you should not use a single instance of YAWriter more than once. For small documents AsArray may be the fastest method and AsString the easiest one to receive the output of YAWriter. But AsString and AsArray may run out of memory with infinite SAX streams. The only method XML::Handler::Writer calls on a given Output object is the print method. So it's easy to use a self written Output object to improve streaming. A single instance of XML::Handler::YAWriter is able to produce more than one file in a single run. Be sure to provide a fresh IO::File as Output before you call start_document and close this File after calling end_document. Or provide a filename in AsFile, so start_document and end_document can open and close its own filehandle. Automatic recoding between 8bit and 16bit does not yet work correctly ! I have Perl-5.00563 at home and here I can specify "use utf8;" in the right places to make recoding work. But I dislike saying "use 5.00555;" because many systems run 5.00503. If you use some 8bit character set internally and want use national characters, either state your character as Encoding to be ISO-8859-1, or provide an Escape hash similar to the following : $ya->{'Escape'} = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', '--' => '--' 'ö' => 'ö' 'ä' => 'ä' 'ü' => 'ü' 'Ö' => 'Ö' 'Ä' => 'Ä' 'Ü' => 'Ü' 'ß' => 'ß' }; You may abuse YAWriter to clean whitespace from XML documents. Take a look at test.pl, doing just that with an XML::Edifact message, without querying the DTD. This may work in 99% of the cases where you want to get rid of ignorable whitespace caused by the various forms of pretty printing. my $ya = new XML::Handler::YAWriter( 'Output' => new IO::File ( ">-" ); 'Pretty' => { 'NoWhiteSpace'=>1, 'NoComments'=>1, 'AddHiddenNewline'=>1, 'AddHiddenAttrTab'=>1, } ); XML::Handler::Writer implements any method XML::Parser::PerlSAX wants. This extends the Java SAX1.0 specification. I have in mind using Pretty=>SAX1=>1 to disable this feature, if abusing YAWriter for a SAX proxy. AUTHOR Michael Koehne, Kraehe@Copyleft.De Thanks "Derksen, Eduard (Enno), CSCIO" helped me with the Escape hash and gave quite a lot of useful comments. SEE ALSO the perl manpage and the XML::Parser::PerlSAX manpage XML-Handler-YAWriter-0.23/MANIFEST0100644000076400000620000000021407317046123015432 0ustar kraehestaffChanges MANIFEST Makefile.PL README YAWriter.pm test.pl linux.1.xml action.xml cdatain.xml directory.xml nullin.xml edifact03.dtd xmlpretty XML-Handler-YAWriter-0.23/directory.xml0100644000076400000620000000075207257745040017045 0ustar kraehestaff XML-Handler-YAWriter-0.23/test.pl0100644000076400000620000000620007316576367015637 0ustar kraehestaff# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..5\n"; } END {print "not ok 1\n" unless $loaded;} use XML::Handler::YAWriter; use XML::Parser::PerlSAX; use IO::File; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): my $xml_file = new IO::File( '>linux.2.xml' ); my $handler = new XML::Handler::YAWriter( 'Output' => $xml_file, 'Pretty' => { 'CatchWhiteSpace' => 1 } ); my $parser = new XML::Parser::PerlSAX( 'Handler' => $handler ); $parser->parse( 'Source' => { 'SystemId' => 'linux.1.xml' } ); $xml_file->close(); print "ok 2\n"; $xml_file = new IO::File( '>linux.3.xml' ); $handler->{'Output'} = $xml_file; $handler->{'Pretty'}{'CatchWhiteSpace'}=0; $handler->{'Pretty'}{'NoWhiteSpace'}=1; $handler->{'Pretty'}{'NoComments'}=1; $handler->{'Pretty'}{'AddHiddenNewline'}=1; $handler->{'Pretty'}{'AddHiddenAttrTab'}=1; $parser->parse( 'Source' => { 'SystemId' => 'linux.1.xml' } ); $xml_file->close(); print "ok 3\n"; $handler->{'AsFile'} = 'linux.4.xml'; $handler->{'Pretty'}{'CatchWhiteSpace'}=0; $handler->{'Pretty'}{'NoWhiteSpace'}=0; $handler->{'Pretty'}{'NoComments'}=0; $handler->{'Pretty'}{'AddHiddenNewline'}=0; $handler->{'Pretty'}{'AddHiddenAttrTab'}=0; $handler->{'Pretty'}{'PrettyWhiteNewline'}=1; $handler->{'Pretty'}{'PrettyWhiteIndent'}=1; $parser->parse( 'Source' => { 'SystemId' => 'linux.3.xml' } ); print "ok 4\n"; $handler->{'AsFile'} = 'action.tst'; $handler->{'Pretty'} = { NoProlog => 1, NoWhiteSpace => 1, CatchEmptyElement => 1, PrettyWhiteIndent => 1, PrettyWhiteNewline => 1 }; $parser->parse( 'Source' => { 'SystemId' => 'action.xml' } ); print "ok 5\n"; $handler->{'AsFile'} = 'directory.tst'; $handler->{'Pretty'} = { 'NoWhiteSpace' => 1, 'PrettyWhiteNewLine' => 1, 'PrettyWhiteIndent' => 1, 'CatchEmptyElement' => 1, 'AddHiddenAttrTab' => 1, 'CompactAttrIndent' => 1 }; $parser->parse( 'Source' => { 'SystemId' => 'directory.xml' } ); print "ok 6\n"; $handler->{'AsFile'} = 'cdataout.xml'; $handler->{'Pretty'} = { 'NoWhiteSpace' => 1, 'PrettyWhiteNewLine' => 1, 'PrettyWhiteIndent' => 1, 'CatchEmptyElement' => 1, 'CompactAttrIndent' => 1 }; $parser->parse( 'Source' => { 'SystemId' => 'cdatain.xml' } ); print "ok 7\n"; $handler->{'AsFile'} = 'nullout.xml'; $handler->{'Pretty'} = { CompactAttrIndent => 1, NoComments => 1, PrettyWhiteNewline => 1, PrettyWhiteIndent => 1, NoWhiteSpace => 1, CatchEmptyElement => 1 }; $parser->parse( 'Source' => { 'SystemId' => 'nullin.xml' } ); print "ok 8\n"; XML-Handler-YAWriter-0.23/Changes0100644000076400000620000000022007055016013015563 0ustar kraehestaffRevision history for Perl extension XML::Handler::YAWriter. 0.10 Tue Nov 30 01:54:52 1999 - created by extraction from current XML::Edifact XML-Handler-YAWriter-0.23/Makefile.PL0100644000076400000620000000054607245625436016275 0ustar kraehestaffuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'XML::Handler::YAWriter', 'VERSION_FROM' => 'YAWriter.pm', 'EXE_FILES' => [ 'xmlpretty' ], 'PREREQ_PM' => { 'XML::Parser::PerlSAX' => 0.06, 'IO::File' => 1.06 } ); XML-Handler-YAWriter-0.23/action.xml0100644000076400000620000000030507116004742016277 0ustar kraehestaff01 XML-Handler-YAWriter-0.23/linux.1.xml0100644000076400000620000000275007055016013016322 0ustar kraehestaff Operating system Linux 1.2 13 1 XML-Handler-YAWriter-0.23/YAWriter.pm0100644000076400000620000003267107425334734016371 0ustar kraehestaff# # Copyright (c) 1999 Michael Koehne # # XML::Handler::YAWriter is free software. You can redistribute # and/or modify this copy under terms of GNU General Public License. # Based on XML::Handler::XMLWriter Copyright (C) 1999 Ken MacLeod # Portions derived from code in XML::Writer by David Megginson package XML::Handler::YAWriter; use strict; use vars qw($VERSION); $VERSION="0.23"; sub new { my $type = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; return bless $self, $type; } use vars qw($escapes); $escapes = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', '--' => '--' }; sub start_document { my ($self, $document) = @_; my ($lc,$uc); $self->{'Strings'} = []; $self->{'Escape'} = $escapes unless $self->{'Escape'}; $self->{'Encoding'} = "UTF-8" unless $self->{'Encoding'}; if ($self->{'AsFile'}) { require IO::File; $self->{'Output'} = new IO::File(">".$self->{'AsFile'}) || die "$!"; } elsif ($self->{'AsPipe'}) { require IO::File; $self->{'Output'} = new IO::File("|".$self->{'AsPipe'}) || die "$!"; } $self->{'NoString'} = ($self->{'Output'} && ! $self->{'AsArray'}); $self->{'Pretty'} = {} unless ref($self->{'Pretty'}) eq "HASH"; $uc = $self->{'Pretty'}; foreach (keys %$uc) { $lc = lc $_; if ($lc ne $_) { $self->{'Pretty'}{$lc} = $self->{'Pretty'}{$_}; delete $self->{'Pretty'}{$_}; } } $self->{'LeftSPC'} = $self->{'Pretty'}{'prettywhitenewline'} ? "\n" : ""; $self->{'Indent'} = $self->{'Pretty'}{'prettywhiteindent'} ? " " : ""; $self->{'AttrSPC'} = $self->{'Pretty'}{'addhiddenattrtab'} ? "\n\t" : " "; $self->{'ElemSPC'} = $self->{'Pretty'}{'addhiddennewline'} ? "\n" : ""; $self->{'CompactAttr'} = $self->{'Pretty'}{'compactattrindent'}; $self->{'Counter'} = 0; $self->{'Section'} = 0; $self->{LastCount} = 0; $self->{'InCDATA'} = 0; undef $self->{Sendleft}; undef $self->{Sendbuf}; undef $self->{Sendright}; my $sub = 'sub { my ($str,$esc) = @_; $str =~ s/(' . join("|", map { $_ = "\Q$_\E" } keys %{$self->{Escape}}). ')/$esc->{$1}/oge; return $str; }'; $self->{EscSub} = eval $sub; $self->print( undef, "{'Encoding'}."\"?>", undef) unless $self->{'Pretty'}{'noprolog'}; } sub end_document { my ($self, $document) = @_; $self->print(undef,"\n",undef) unless $self->{'LeftSPC'}; $self->print(undef,undef,undef); my $string = undef; $string = join('', @{$self->{Strings}}) if $self->{AsString}; if ($self->{'AsFile'}) { $self->{'Output'}->close(); undef $self->{'Output'}; } return($string); } sub doctype_decl { my ($self, $properties) = @_; return if $self->{'Pretty'}{'nodtd'}; return unless $properties->{'Name'}; my $attspc = $self->{'AttrSPC'}; my $output = "DOCTYPE ".$properties->{'Name'}; $output .= $attspc.'SYSTEM "'.$properties->{'SystemId'}.'"' if $properties->{'SystemId'}; $output .= $attspc.'PUBLIC "'.$properties->{'PublicId'}.'"' if $properties->{'PublicId'}; $output .= $attspc.$properties->{'Internal'} if $properties->{'Internal'}; $self->print(""); } sub processing_instruction { my ($self, $pi) = @_; return if $self->{'Pretty'}{'nopi'}; my $output = undef; $output = $pi->{Target}." " if $pi->{Target}; $output .= $pi->{Data}." " if $pi->{Data}; return unless $output; chop $output; if ($self->{'Pretty'}{issgml}) { $self->print("") } else { $self->print("") } } sub start_element { my ($self, $element) = @_; my $name; my $esc_value; my $attr; my $output = $element->{Name}; my $attrspc= $self->{'AttrSPC'}; $attrspc= "\n".$self->{'Indent'} x (2+$self->{'Counter'}) if $self->{'Indent'}; $attrspc= " " if $self->{'CompactAttr'}; if ($element->{Attributes}) { $attr = $element->{Attributes}; foreach $name (sort keys %$attr) { $esc_value = $self->encode($attr->{$name}); $output .= $attrspc . "$name=\"$esc_value\""; } } $self->print("<", $output, ">"); $self->{'Counter'}++; } sub end_element { my ($self, $element) = @_; my $name = $element->{Name}; $self->{'Counter'}--; if ($self->{'Pretty'}{'catchemptyelement'} && ($self->{Sendbuf} =~ /^$name/ ) && ($self->{Sendleft} eq "<") && ($self->{Sendright} eq ">") ) { $self->{Sendright} = "/>"; } else { $self->print(""); } } sub characters { my ($self, $characters) = @_; return unless defined $characters->{Data}; my $output = $self->{'InCDATA'} ? $characters->{Data} : $self->encode($characters->{Data}); if ($self->{'Pretty'}{'catchwhitespace'} && !$self->{'InCDATA'}) { $output =~ s/^([ \t\n\r]+)//; $self->print("") if $1; return if $output eq ""; $output =~ s/([ \t\n\r]+)\$//; $self->print("") if $1; return if $output eq ""; } elsif ($self->{'Pretty'}{'nowhitespace'} && !$self->{'InCDATA'}) { $output =~ s/^([ \t\n\r]+)//; return if $output eq ""; $output =~ s/([ \t\n\r]+)\$//; return if $output eq ""; } $self->print(undef, $output, undef); } sub ignorable_whitespace { my ($self, $whitespace) = @_; my $output = $whitespace->{Data}; return unless $output; $self->print(""); # $self->print($output, undef, undef); } sub comment { my ($self, $comment) = @_; return if $self->{'Pretty'}{'nocomments'}; my $output = $self->encode($comment->{Data}); return unless $output; $self->print(""); } sub encode { my ($self, $string) = @_; return &{$self->{EscSub}}($string, $self->{'Escape'}); } sub start_cdata { my ($self, $cdata) = @_; $self->{'InCDATA'} = 1; $self->print(undef, '{'InCDATA'} = 0; $self->print(undef, ']]>', undef); } sub print { my ($self, $left, $output, $right) = @_; my $sendbuf = ""; if ($self->{Sendleft}) { $sendbuf .= $self->{'LeftSPC'}; $sendbuf .= $self->{'Indent'} x $self->{'LastCount'} if $self->{'Indent'}; $sendbuf .= $self->{Sendleft}; } $sendbuf .= $self->{Sendbuf} if defined $self->{Sendbuf}; $sendbuf .= $self->{'ElemSPC'}.$self->{Sendright} if $self->{Sendright}; if ($sendbuf ne "") { $self->{Output}->print( $sendbuf ) if $self->{Output}; push(@{$self->{Strings}}, $sendbuf) unless $self->{NoString}; } $self->{Sendleft} = $left; $self->{Sendbuf} = $output; $self->{Sendright} = $right; $self->{LastCount} = $self->{'Counter'}; } 1; =head1 NAME XML::Handler::YAWriter - Yet another Perl SAX XML Writer =head1 SYNOPSIS use XML::Handler::YAWriter; my $ya = new XML::Handler::YAWriter( %options ); my $perlsax = new XML::Parser::PerlSAX( 'Handler' => $ya ); =head1 DESCRIPTION YAWriter implements Yet Another XML::Handler::Writer. The reasons for this one are that I needed a flexible escaping technique, and want some kind of pretty printing. If an instance of YAWriter is created without any options, the default behavior is to produce an array of strings containing the XML in : @{$ya->{Strings}} =head2 Options Options are given in the usual 'key' => 'value' idiom. =over =item Output IO::File This option tells YAWriter to use an already open file for output, instead of using $ya->{Strings} to store the array of strings. It should be noted that the only thing the object needs to implement is the print method. So anything can be used to receive a stream of strings from YAWriter. =item AsFile string This option will cause start_document to open named file and end_document to close it. Use the literal dash "-" if you want to print on standard output. =item AsPipe string This option will cause start_document to open a pipe and end_document to close it. The pipe is a normal shell command. Secure shell comes handy but has a 2GB limit on most systems. =item AsArray boolean This option will force storage of the XML in $ya->{Strings}, even if the Output option is given. =item AsString boolean This option will cause end_document to return the complete XML document in a single string. Most SAX drivers return the value of end_document as a result of their parse method. As this may not work with some combinations of SAX drivers and filters, a join of $ya->{Strings} in the controlling method is preferred. =item Encoding string This will change the default encoding from UTF-8 to anything you like. You should ensure that given data are already in this encoding or provide an Escape hash, to tell YAWriter about the recoding. =item Escape hash The Escape hash defines substitutions that have to be done to any string, with the exception of the processing_instruction and doctype_decl methods, where I think that escaping of target and data would cause more trouble than necessary. The default value for Escape is $XML::Handler::YAWriter::escape = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', '--' => '--' }; YAWriter will use an evaluated sub to make the recoding based on a given Escape hash reasonably fast. Future versions may use XS to improve this performance bottleneck. =item Pretty hash Hash of string => boolean tuples, to define kind of prettyprinting. Default to undef. Possible string values: =over =item AddHiddenNewline boolean Add hidden newline before ">" =item AddHiddenAttrTab boolean Add hidden tabulation for attributes =item CatchEmptyElement boolean Catch empty Elements, apply "/>" compression =item CatchWhiteSpace boolean Catch whitespace with comments =item CompactAttrIndent Places Attributes on the same line as the Element =item IsSGML boolean This option will cause start_document, processing_instruction and doctype_decl to appear as SGML. The SGML is still well-formed of course, if your SAX events are well-formed. =item NoComments boolean Supress Comments =item NoDTD boolean Supress DTD =item NoPI boolean Supress Processing Instructions =item NoProlog boolean Supress Prolog =item NoWhiteSpace boolean Supress WhiteSpace to clean documents from prior pretty printing. =item PrettyWhiteIndent boolean Add visible indent before any eventstring =item PrettyWhiteNewline boolean Add visible newlines before any eventstring =item SAX1 boolean (not yet implemented) Output only SAX1 compliant eventstrings =back =back =head2 Notes: Correct handling of start_document and end_document is required! The YAWriter Object initialises its structures during start_document and does its cleanup during end_document. If you forget to call start_document, any other method will break during the run. Most likely place is the encode method, trying to eval undef as a subroutine. If you forget to call end_document, you should not use a single instance of YAWriter more than once. For small documents AsArray may be the fastest method and AsString the easiest one to receive the output of YAWriter. But AsString and AsArray may run out of memory with infinite SAX streams. The only method XML::Handler::Writer calls on a given Output object is the print method. So it's easy to use a self written Output object to improve streaming. A single instance of XML::Handler::YAWriter is able to produce more than one file in a single run. Be sure to provide a fresh IO::File as Output before you call start_document and close this File after calling end_document. Or provide a filename in AsFile, so start_document and end_document can open and close its own filehandle. Automatic recoding between 8bit and 16bit does not work in any Perl correctly ! I have Perl-5.00563 at home and here I can specify "use utf8;" in the right places to make recoding work. But I dislike saying "use 5.00555;" because many systems run 5.00503. If you use some 8bit character set internally and want use national characters, either state your character as Encoding to be ISO-8859-1, or provide an Escape hash similar to the following : $ya->{'Escape'} = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', '--' => '--' 'ö' => 'ö' 'ä' => 'ä' 'ü' => 'ü' 'Ö' => 'Ö' 'Ä' => 'Ä' 'Ü' => 'Ü' 'ß' => 'ß' }; You may abuse YAWriter to clean whitespace from XML documents. Take a look at test.pl, doing just that with an XML::Edifact message, without querying the DTD. This may work in 99% of the cases where you want to get rid of ignorable whitespace caused by the various forms of pretty printing. my $ya = new XML::Handler::YAWriter( 'Output' => new IO::File ( ">-" ); 'Pretty' => { 'NoWhiteSpace'=>1, 'NoComments'=>1, 'AddHiddenNewline'=>1, 'AddHiddenAttrTab'=>1, } ); XML::Handler::Writer implements any method XML::Parser::PerlSAX wants. This extends the Java SAX1.0 specification. I have in mind using Pretty=>SAX1=>1 to disable this feature, if abusing YAWriter for a SAX proxy. =head1 AUTHOR Michael Koehne, Kraehe@Copyleft.De =head1 Thanks "Derksen, Eduard (Enno), CSCIO" helped me with the Escape hash and gave quite a lot of useful comments. =head1 SEE ALSO L and L =cut XML-Handler-YAWriter-0.23/cdatain.xml0100644000076400000620000000067607264660720016450 0ustar kraehestaff
AceFighterRenderPluginF16LCAHarrier]]> XML-Handler-YAWriter-0.23/xmlpretty0100644000076400000620000000635307123542201016277 0ustar kraehestaff#!/usr/bin/perl use strict; use XML::Handler::YAWriter; use XML::Parser::PerlSAX; use IO::File; my $options; $options->{Output} = new IO::File(">-"); while ($ARGV[0] =~ "^--") { my $opt=shift @ARGV; $opt =~ s/^--//; $options->{Pretty}{$opt}=1; } my $file = new IO::File( $#ARGV >=0 ? "<".$ARGV[0] : "<-" ); my $ya = new XML::Handler::YAWriter( $options ); my $perlsax = new XML::Parser::PerlSAX( 'Handler' => $ya, 'Source' => { ByteStream => $file } ); $perlsax->parse(); 0; =head1 NAME xmlpretty - XML pretty printer =head1 SYNOPSIS xmlpretty [--options] [filename] =head1 DESCRIPTION B is the commandline interface to XML::Handler::YAWriter, acting as a tool to add and remove pretty printing to XML files. B has several methods to add human readablitiy. If you want to add readablity without adding so-called I, use it in the following way : $ xmlpretty --AddHiddenNewline \ --AddHiddenAttrTab \ --CatchEmptyElement \ uglyfile.xml > prettyfile.xml If you do B want to process the file further, but only want it human readable, add visible whitespace to the file as follows : $ xmlpretty --PrettyWhiteNewline \ --PrettyWhiteIndent \ --CatchEmptyElement \ uglyfile.xml > prettyfile.xml You may use YAWriter to clean whitespace from XML documents. This may work in 99% of the cases where you want to get rid of ignorable whitespace caused by the various forms of pretty printing. $ xmlpretty --NoWhiteSpace \ --NoComments \ --AddHiddenNewline \ --AddHiddenAttrTab \ --CatchEmptyElement \ prettyfile.xml > cleanfile.xml =head2 Options Options are given in a gnu like --option idiom. =over =item AddHiddenNewline boolean Add hidden newline before ">" =item AddHiddenAttrTab boolean Add hidden tabulation for attributes =item CatchEmptyElement boolean Catch empty Elements, apply "/>" compression =item CatchWhiteSpace boolean Catch whitespace with comments =item IsSGML boolean This option will cause start_document, processing_instruction and doctype_decl to appear as SGML. The SGML is still well-formed of course, if your SAX events are well-formed. =item NoComments boolean Supress Comments =item NoDTD boolean Supress DTD =item NoPI boolean Supress Processing Instructions =item NoProlog boolean Supress Prolog =item NoWhiteSpace boolean Supress WhiteSpace to clean documents from prior pretty printing. =item PrettyWhiteIndent boolean Add visible indent before any eventstring =item PrettyWhiteNewline boolean Add visible newlines before any eventstring =item SAX1 boolean (not yet implemented) Output only SAX1 compilant eventstrings =back =head2 Bugs: Automatic recoding between 8bit and 16bit does not yet work correctly ! I have Perl-5.6 at home and here I can specify "use utf8;" in the right places to make recoding work. But I dislike saying "use 5.00555;" because many systems run 5.00503. =head1 AUTHOR Michael Koehne, Kraehe@Copyleft.De =head1 Thanks "Derksen, Eduard (Enno), CSCIO" helped me with the Escape hash and gave quite a lot of usefull comments. =head1 SEE ALSO L and L =cut XML-Handler-YAWriter-0.23/nullin.xml0100644000076400000620000000003707316576351016341 0ustar kraehestaff0 0