# # $Id: //depot/isms/skulker/cbd/1.1/lib/cbd-xml.pl#2 $ # # file: cbd-xml.pl # desc: CBD XML generation support # # limit scope package CBD::XML; # CBD to XML DTD (for validation) my $DTD = 'http://xml.resource.org/doc/cbd/cbd.dtd'; my $DOCTYPE = qq|PUBLIC "-//Blocks//DTD CBD//EN" "$DTD"|; ## for test/debug - bjb, 26-apr-1999 #my $DTD = 'cbdtest.dtd'; #my $DOCTYPE = qq|SYSTEM "$DTD"|; # # generate standard XML header # sub header { my($cbd) = shift; # header we will build and return my($hdr); # XML version $hdr = "" . "\n"; # will this change? $hdr .= "" . "\n\n"; $hdr .= "" . "\n"; $hdr; } # # XML transformer info # sub transformer { my($cbd) = shift; my($xml) = ''; # transform date my($date) = `/bin/date +"%d-%h-%Y, %T %Z"`; chomp($date); $xml = < Invisible Worlds, Inc.
1179 N. McDowell Blvd Petaluma California 94954 US webmaster\@invisible.net http://invisible.net/
$date EoD $xml; } # # generate standard XML trailer # sub trailer { my($cbd) = shift; my($trlr); $trlr .= "\n"; $trlr .= "
" . "\n"; $trlr; } # # encode reserved characters # sub encode { my($foo) = shift; # $foo = XML::Parser::Expat::xml_escape($foo); # special case -- CBD SGML ENTITY values $foo =~ s/ / /g; $foo =~ s/ / /g; $foo =~ s/&llmdash;/_/g; $foo =~ s/—/ -- /g; $foo =~ s/–/ - /g; $foo =~ s/∼/ /g; # avoid double encoding & $foo =~ s/&/&/g; # order is important with & substitution -- keep it first $foo =~ s/&/&/g; $foo; } # # decode reserved characters # sub decode { my($foo) = shift; $foo =~ s/&/&/g; $foo; } # # remove trailing and leading spaces # sub trim { my($text) = shift; $text =~ s/^\s+|\s+$//g; $text; } # # encode attribute values properly # sub encode_av { my($foo) = shift; # $foo = XML::Parser::Expat::xml_escape($foo); # remove trailing and leading spaces $foo = trim($foo); # avoid double encoding & $foo =~ s/&/&/g; # order is important with & substitution -- keep it first $foo =~ s/&/\&/g; $foo =~ s/'/\'/g; $foo =~ s/"/\"/g; $foo =~ s//\>/g; return "\"$foo\""; } # keep require happy -- DO NOT REMOVE 1; =head1 NAME cbd-xml.pl - XML specific processing =head1 PACKAGE CBD::XML =head1 SYNOPSIS require cbd-xml.pl; =head1 REQUIRED Perl, version 5.001 or higher =head1 DESCRIPTION XML Specific processing routines. =over 3 =head1 METHODS =head2 header =item * generates standard XML header =item * An XML header is returned. =item example: my ($header) = &CBD::XML::header($cbd); =head2 transformer =item * generates transformer information for CBD doc =item * An XML transformer string is returned. =item example: my ($transformer) = &CBD::XML::transformer($cbd); item example XML: Invisible Worlds, Inc.
660 York Street San Francisco California 94110 U/country edgar@invisible.net http://invisible.net/
01-12-1999 ftp://ftp.sec.gov/edgar/data/888/777777.txt
=head2 trim =item * Removes leading and trailing spaces from a string =item example: $str = &CBD::XML::trim($str); =head2 encode_av =item * Encodes entities such as &, >, <, " and ' =item example: $str = &CBD::XML::encode_av($str); =item encoding performed: & --> & < --> < =head2 encode =item * Encodes entities such as &mdash, &llmdash, &sim =item example: $str = &CBD::XML::encode($str); =item encoding performed: &mdash --> -- &llmdash --> -- =back =head1 COPYRIGHT Copyright 1999 Invisible Worlds. =head1 AUTHOR CBD::XML was written by Gautam Yegnanarayan . =cut