XML::SAX::RTF - SAX Driver for Microsoft's Rich Text Format (RTF)
use XML::SAX::ParserFactory; use XML::SAX::RTF; my $handler = new MyHandler; my $parser = XML::SAX::ParserFactory->parser( Handler => $handler ); $parser->parse_file( shift @ARGV ); package MyHandler; sub new { my $class = shift; my $self = {@_}; return bless( $self, $class ); } sub start_element { my( $self, $data ) = @_; print "<", $data->{Name}; if( exists( $data->{Attributes} )) { my %atts = %{$data->{Attributes}}; foreach my $att ( keys %atts ) { my $val = $atts{$att}; $val =~ s/\"/"/g; print " $att=\"$val\""; } } print ">"; } sub end_element { my( $self, $data ) = @_; print "</", $data->{Name}, ">"; } sub characters { my( $self, $data ) = @_; print $data->{Data}; }
This is a subclass of XML::SAX::Base which implements a SAX driver for RTF documentation. It generates XML that closely matches the structure of RTF, i.e. a set of paragraph types with text and inline tags inside.
Erik Ray (eray@oreilly.com)
Copyright 2002 Erik Ray and O'Reilly & Associates Inc.
To install XML::SAX::RTF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::SAX::RTF
CPAN shell
perl -MCPAN -e shell install XML::SAX::RTF
For more information on module installation, please visit the detailed CPAN module installation guide.