deprecated/buildtools/buildsystemtools/lib/XML/Handler/Composer.pm
author lorewang
Thu, 11 Nov 2010 11:26:32 +0800
changeset 677 44e49837144a
parent 655 3f65fd25dfd4
permissions -rw-r--r--
update release info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
package XML::Handler::Composer;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
use XML::UM;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
use vars qw{ %DEFAULT_QUOTES %XML_MAPPING_CRITERIA };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
%DEFAULT_QUOTES = (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
		   XMLDecl => '"', 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
		   Attr => '"',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
		   Entity => '"',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
		   SystemLiteral => '"',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
		  );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
%XML_MAPPING_CRITERIA = 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
(
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
 Text => 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
   '<' => '&lt;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
   '&' => '&amp;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
   ']]>' => ']]&gt;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
 CDataSection => 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
   ']]>' => ']]&gt;',	# NOTE: this won't be translated back correctly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
 Attr =>	# attribute value (assuming double quotes "" are used)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
#   '"' => '&quot;',	# Use ("'" => '&apos;') when using single quotes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
   '<' => '&lt;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
   '&' => '&amp;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
 Entity =>	# entity value (assuming double quotes "" are used)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
#   '"' => '&quot;',	# Use ("'" => '&apos;') when using single quotes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
   '%' => '&#37;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
   '&' => '&amp;',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
 Comment => 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
   '--' => '&#45;&#45;',	# NOTE: this won't be translated back correctly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
 ProcessingInstruction =>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
   '?>' => '?&gt;',	# not sure if this will be translated back correctly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
 # The SYSTEM and PUBLIC identifiers in DOCTYPE declaration (quoted strings)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
 SystemLiteral => 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
 {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
#   '"' => '&quot;',	# Use ("'" => '&apos;') when using single quotes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
 },
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
sub new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
    my ($class, %options) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
    my $self = bless \%options, $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
    $self->{EndWithNewline} = 1 unless defined $self->{EndWithNewline};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
    if (defined $self->{Newline})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
	$self->{ConvertNewlines} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
	# Use this when printing newlines in case the user didn't specify one
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
	$self->{Newline} = "\x0A";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
    $self->{DocTypeIndent}  = $self->{Newline} . "  " 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
	unless defined $self->{DocTypeIndent};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
    $self->{IndentAttlist}  = "        " unless defined $self->{IndentAttlist};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
    $self->{Print}	    = sub { print @_ } unless defined $self->{Print};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
    $self->{Quote} ||= {};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
    for my $q (keys %DEFAULT_QUOTES)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
	$self->{Quote}->{$q} ||= $DEFAULT_QUOTES{$q};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
    # Convert to UTF-8 by default, i.e. when <?xml encoding=...?> is missing 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
    # and no {Encoding} is specified.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
    # Note that the internal representation *is* UTF-8, so we
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
    # simply return the (string) parameter.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
    $self->{Encode} = sub { shift } unless defined $self->{Encode};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
    # Convert unmapped characters to hexadecimal constants a la '&#x53F7;'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
    $self->{EncodeUnmapped} = \&XML::UM::encode_unmapped_hex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
	unless defined $self->{EncodeUnmapped};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
    my $encoding = $self->{Encoding};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
    $self->setEncoding ($encoding) if defined $encoding;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
    $self->initMappers;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
    $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
# Setup the mapping routines that convert '<' to '&lt;' etc.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
# for the specific XML constructs.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
sub initMappers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
    my %escape;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
    my $convert_newlines = $self->{ConvertNewlines};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
    for my $n (qw{ Text Comment CDataSection Attr SystemLiteral
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
		   ProcessingInstruction Entity })
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
	$escape{$n} = $self->create_utf8_mapper ($n, $convert_newlines);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
    # Text with xml:space="preserve", should not have newlines converted.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
    $escape{TextPreserveNL} = $self->create_utf8_mapper ('Text', 0);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
    # (If newline conversion is inactive, $escape{TextPreserveNL} does the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
    # same as $escape{Text} defined above ...)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
    $self->{Escape} = \%escape;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
sub setEncoding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
    my ($self, $encoding) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
    $self->{Encode} = XML::UM::get_encode (
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
	Encoding => $encoding, EncodeUnmapped => $self->{EncodeUnmapped});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
sub create_utf8_mapper
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
    my ($self, $construct, $convert_newlines) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    my $c = $XML_MAPPING_CRITERIA{$construct};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
    croak "no XML mapping criteria defined for $construct" 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
           unless defined $c;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
    my %hash = %$c;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
    # If this construct appears between quotes in the XML document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
    # (and it has a quoting character defined), 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
    # ensure that the quoting character is appropriately converted
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
    # to &quot; or &apos;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
    my $quote = $self->{Quote}->{$construct};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
    if (defined $quote)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
	$hash{$quote} = $quote eq '"' ? '&quot;' : '&apos;';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
    if ($convert_newlines)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
	$hash{"\x0A"} = $self->{Newline};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
    gen_utf8_subst (%hash);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
# Converts a string literal e.g. "ABC" into '\x41\x42\x43'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
# so it can be stuffed into a regular expression
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
sub str_to_hex		# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
    my $s = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
    $s =~ s/(.)/ sprintf ("\\x%02x", ord ($1)) /egos;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
    $s;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
# In later perl versions (5.005_55 and up) we can simply say:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
# use utf8;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
# $literals = join ("|", map { str_to_hex ($_) } keys %hash);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
# $s =~ s/($literals)/$hash{$1}/ego;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
sub gen_utf8_subst	# static
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
    my (%hash) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
    my $code = 'sub { my $s = shift; $s =~ s/(';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
    $code .= join ("|", map { str_to_hex ($_) } keys %hash);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
    $code .= ')|(';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
    $code .= '[\\x00-\\xBF]|[\\xC0-\\xDF].|[\\xE0-\\xEF]..|[\\xF0-\\xFF]...';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
    $code .= ')/ defined ($1) ? $hash{$1} : $2 /ego; $s }';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
    my $f = eval $code;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
    croak "XML::Handler::Composer - can't eval code: $code\nReason: $@" if $@;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
    $f;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
# This should be optimized!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
sub print
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
    my ($self, $str) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
    $self->{Print}->($self->{Encode}->($str));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
# Used by start_element. It determines the style in which empty elements
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
# are printed. The default implementation returns "/>" so they are printed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
# like this: <a/>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
# Override this method to support e.g. XHTML style tags. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
sub get_compressed_element_suffix
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
    "/>";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
    # return " />" for XHTML style, or
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
    # "><$tagName/>" for uncompressed tags (where $tagName is $event->{Name})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
#----- PerlSAX handlers -------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
sub start_document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
    $self->{InCDATA} = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
    $self->{DTD} = undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
    $self->{PreserveWS} = 0;	# root element has xml:space="default"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
    $self->{PreserveStack} = [];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
    $self->{PrintedXmlDecl} = 0;	# whether <?xml ...?> was printed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
sub end_document
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
    # Print final Newline at the end of the XML document (if desired)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
    $self->print ($self->{Newline}) if $self->{EndWithNewline};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
# This event is received *AFTER* the Notation, Element, Attlist etc. events 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
# that are contained within the DTD.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
sub doctype_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
    my $q = $self->{Quote}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
    my $escape_literal = $self->{Escape}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
    my $name = $event->{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
    my $sysId = $event->{SystemId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
    $sysId = &$escape_literal ($sysId) if defined $sysId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
    my $pubId = $event->{PublicId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
    $pubId = &$escape_literal ($pubId) if defined $pubId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
    my $str = "<!DOCTYPE $name";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
	$str .= " PUBLIC $q$pubId$q $q$sysId$q";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
    elsif (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
	$str .= " SYSTEM $q$sysId$q";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
    my $dtd_contents = $self->{DTD};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
    my $nl = $self->{Newline};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
    if (defined $dtd_contents)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
	delete $self->{DTD};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
	$str .= " [$dtd_contents$nl]>$nl";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
	$str .= ">$nl";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
    $self->print ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
sub start_element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
    my $preserve_stack = $self->{PreserveStack};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
    if (@$preserve_stack == 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
	# This is the root element. Print the <?xml ...?> declaration now if
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
	# it wasn't printed and it should be.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
	$self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
    my $str = "<" . $event->{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
    my $suffix = ">";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
    if ($event->{Compress})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
	$suffix = $self->get_compressed_element_suffix ($event);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
    # Push PreserveWS state of parent element on the stack
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
    push @{ $preserve_stack }, $self->{PreserveWS};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
    $self->{PreserveWS} = $event->{PreserveWS};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
    my $ha = $event->{Attributes};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
    my @attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
    if (exists $event->{AttributeOrder})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
	my $defaulted = $event->{Defaulted};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
	if (defined $defaulted && !$self->{PrintDefaultAttr})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
	    if ($defaulted > 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
		@attr = @{ $event->{AttributeOrder} }[0 .. $defaulted - 1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
	    # else: all attributes are defaulted i.e. @attr = ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
	else	# no attr are defaulted
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
	    @attr = @{ $event->{AttributeOrder} };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
    else	# no attr order defined
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
	@attr = keys %$ha;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
    my $escape = $self->{Escape}->{Attr};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
    my $q = $self->{Quote}->{Attr};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
    for (my $i = 0; $i < @attr; $i++)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
#?? could print a newline every so often...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
	my $name = $attr[$i];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
	my $val = &$escape ($ha->{$name});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
	$str .= " $name=$q$val$q";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
    $str .= $suffix;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
    $self->print ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
sub end_element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
    $self->{PreserveWS} = pop @{ $self->{PreserveStack} };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
    return if $event->{Compress};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
    $self->print ("</" . $event->{Name} . ">");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
sub characters
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
    if ($self->{InCDATA})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
#?? should this use $self->{PreserveWS} ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
	my $esc = $self->{Escape}->{CDataSection};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
	$self->print (&$esc ($event->{Data}));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
    else # regular text
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
	my $esc = $self->{PreserveWS} ? 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
	    $self->{Escape}->{TextPreserveNL} :
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
	    $self->{Escape}->{Text};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
	$self->print (&$esc ($event->{Data}));
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
sub start_cdata
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
    $self->{InCDATA} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
    $self->print ("<![CDATA[");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
sub end_cdata
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
    $self->{InCDATA} = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
    $self->print ("]]>");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
sub comment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
    my $esc = $self->{Escape}->{Comment};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
#?? still need to support comments in the DTD
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
    $self->print ("<!--" . &$esc ($event->{Data}) . "-->");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
sub entity_reference
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
    my $par = $event->{Parameter} ? '%' : '&';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
#?? parameter entities (like %par;) are NOT supported!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
# PerlSAX::handle_default should be fixed!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
    $self->print ($par . $event->{Name} . ";");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
sub unparsed_entity_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
    $self->entity_decl ($event);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
sub notation_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
    my $name = $event->{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
    my $sysId = $event->{SystemId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
    my $pubId = $event->{PublicId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
    my $q = $self->{Quote}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
    my $escape = $self->{Escape}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
    $sysId = &$escape ($sysId) if defined $sysId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
    $pubId = &$escape ($pubId) if defined $pubId;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
    my $str = $self->{DocTypeIndent} . "<!NOTATION $name";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
	$str .= " PUBLIC $q$pubId$q";	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
    if (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
	$str .= " SYSTEM $q$sysId$q";	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
    $str .= ">";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
    $self->{DTD} .= $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
sub element_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
    my $name = $event->{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
    my $model = $event->{Model};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
    $self->{DTD} .= $self->{DocTypeIndent} . "<!ELEMENT $name $model>";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   472
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   473
sub entity_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   474
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   475
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   476
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   477
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   478
    my $name = $event->{Name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   479
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   480
    my $par = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   481
    if ($name =~ /^%/)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   482
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   483
	# It's a parameter entity (i.e. %ent; instead of &ent;)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   484
	$name = substr ($name, 1);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   485
	$par = "% ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   486
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   487
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   488
    my $str = $self->{DocTypeIndent} . "<!ENTITY $par$name";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   489
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   490
    my $value = $event->{Value};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   491
    my $sysId = $event->{SysId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   492
    my $pubId = $event->{PubId};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   493
    my $ndata = $event->{Ndata};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   494
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   495
    my $q = $self->{Quote}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   496
    my $escape = $self->{Escape}->{SystemLiteral};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   497
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   498
    if (defined $value)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   499
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   500
#?? use {Entity} quote etc...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   501
	my $esc = $self->{Escape}->{Entity};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   502
	my $p = $self->{Quote}->{Entity};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   503
	$str .= " $p" . &$esc ($value) . $p;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   504
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   505
    if (defined $pubId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   506
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   507
	$str .= " PUBLIC $q" . &$escape ($pubId) . $q;	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   508
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   509
    elsif (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   510
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   511
	$str .= " SYSTEM";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   512
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   513
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   514
    if (defined $sysId)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   515
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   516
	$str .= " $q" . &$escape ($sysId) . $q;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   517
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   518
    $str .= " NDATA $ndata" if defined $ndata;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   519
    $str .= ">";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   520
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   521
    $self->{DTD} .= $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   522
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   523
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   524
sub attlist_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   525
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   526
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   527
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   528
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   529
    my $elem = $event->{ElementName};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   530
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   531
    my $str = $event->{AttributeName} . " " . $event->{Type};    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   532
    $str .= " #FIXED" if defined $event->{Fixed};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   533
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   534
    $str = $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   535
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   536
    my $def = $event->{Default};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   537
    if (defined $def)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   538
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   539
	$str .= " $def";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   540
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   541
	# Note sometimes Default is a value with quotes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   542
	# We'll use the existing quotes in that case...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   543
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   544
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   545
    my $indent;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   546
    if (!exists($event->{First}) || $event->{First})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   547
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   548
	$self->{DTD} .= $self->{DocTypeIndent} . "<!ATTLIST $elem";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   549
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   550
	if ($event->{MoreFollow})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   551
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   552
	    $indent = $self->{Newline} . $self->{IndentAttlist};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   553
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   554
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   555
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   556
	    $indent = " ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   557
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   558
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   559
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   560
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   561
	$indent = $self->{Newline} . $self->{IndentAttlist};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   562
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   563
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   564
    $self->{DTD} .= $indent . $str;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   565
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   566
    unless ($event->{MoreFollow})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   567
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   568
	$self->{DTD} .= '>';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   569
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   570
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   571
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   572
sub xml_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   573
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   574
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   575
    return if $self->{PrintedXmlDecl};	# already printed it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   576
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   577
    my $version = $event->{Version};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   578
    my $encoding = $event->{Encoding};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   579
    if (defined $self->{Encoding})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   580
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   581
	$encoding = $self->{Encoding};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   582
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   583
    else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   584
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   585
	$self->setEncoding ($encoding) if defined $encoding;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   586
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   587
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   588
    my $standalone = $event->{Standalone};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   589
    $standalone = ($standalone ? "yes" : "no") if defined $standalone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   590
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   591
    my $q = $self->{Quote}->{XMLDecl};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   592
    my $nl = $self->{Newline};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   593
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   594
    my $str = "<?xml";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   595
    $str .= " version=$q$version$q"	  if defined $version;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   596
    $str .= " encoding=$q$encoding$q"	  if defined $encoding;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   597
    $str .= " standalone=$q$standalone$q" if defined $standalone;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   598
    $str .= "?>$nl$nl";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   599
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   600
    $self->print ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   601
    $self->{PrintedXmlDecl} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   602
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   603
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   604
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   605
# Prints the <xml ...?> declaration if it wasn't already printed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   606
# *and* the user wanted it to be printed (because s/he set $self->{Encoding})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   607
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   608
sub flush_xml_decl
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   609
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   610
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   611
    return if $self->{PrintedXmlDecl};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   612
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   613
    if (defined $self->{Encoding})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   614
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   615
	$self->xml_decl ({ Version => '1.0', Encoding => $self->{Encoding} });
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   616
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   617
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   618
    # If it wasn't printed just now, it doesn't need to be printed at all,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   619
    # so pretend we did print it.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   620
    $self->{PrintedXmlDecl} = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   621
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   622
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   623
sub processing_instruction
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   624
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   625
    my ($self, $event) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   626
    $self->flush_xml_decl;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   627
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   628
    my $escape = $self->{Escape}->{ProcessingInstruction};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   629
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   630
    my $str = "<?" . $event->{Target} . " " . 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   631
		&$escape ($event->{Data}). "?>";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   632
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   633
    $self->print ($str);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   634
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   635
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   636
1; # package return code
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   637
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   638
__END__
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   639
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   640
=head1 NAME
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   641
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   642
XML::Handler::Composer - Another XML printer/writer/generator
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   643
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   644
=head1 SYNOPSIS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   645
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   646
use XML::Handler::Composer;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   647
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   648
my $composer = new XML::Handler::Composer ( [OPTIONS] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   649
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   650
=head1 DESCRIPTION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   651
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   652
XML::Handler::Composer is similar to XML::Writer, XML::Handler::XMLWriter,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   653
XML::Handler::YAWriter etc. in that it generates XML output.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   654
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   655
This implementation may not be fast and it may not be the best solution for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   656
your particular problem, but it has some features that may be missing in the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   657
other implementations:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   658
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   659
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   660
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   661
=item * Supports every output encoding that L<XML::UM> supports
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   662
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   663
L<XML::UM> supports every encoding for which there is a mapping file 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   664
in the L<XML::Encoding> distribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   665
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   666
=item * Pretty printing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   667
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   668
When used with L<XML::Filter::Reindent>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   669
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   670
=item * Fine control over which kind of quotes are used
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   671
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   672
See options below.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   673
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   674
=item * Supports PerlSAX interface
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   675
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   676
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   677
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   678
=head1 Constructor Options
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   679
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   680
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   681
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   682
=item * EndWithNewline (Default: 1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   683
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   684
Whether to print a newline at the end of the file (i.e. after the root element)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   685
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   686
=item * Newline (Default: undef)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   687
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   688
If defined, which newline to use for printing.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   689
(Note that XML::Parser etc. convert newlines into "\x0A".)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   690
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   691
If undef, newlines will not be converted and XML::Handler::Composer will
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   692
use "\x0A" when printing.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   693
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   694
A value of "\n" will convert the internal newlines into the platform
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   695
specific line separator.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   696
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   697
See the PreserveWS option in the characters event (below) for finer control
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   698
over when newline conversion is active.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   699
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   700
=item * DocTypeIndent (Default: a Newline and 2 spaces)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   701
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   702
Newline plus indent that is used to separate lines inside the DTD.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   703
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   704
=item * IndentAttList (Default: 8 spaces)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   705
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   706
Indent used when printing an <!ATTLIST> declaration that has more than one
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   707
attribute definition, e.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   708
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   709
 <!ATTLIST my_elem
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   710
        attr1 CDATA "foo"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   711
        attr2 CDATA "bar"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   712
 >
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   713
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   714
=item * Quote (Default: { XMLDecl => '"', Attr => '"', Entity => '"', SystemLiteral => '"' })
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   715
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   716
Quote contains a reference to a hash that defines which quoting characters 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   717
to use when printing XML declarations (XMLDecl), attribute values (Attr), 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   718
<!ENTITY> values (Entity) and system/public literals (SystemLiteral) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   719
as found in <!DOCTYPE>, <!ENTITY> declarations etc.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   720
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   721
=item * PrintDefaultAttr (Default: 0)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   722
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   723
If 1, prints attribute values regardless of whether they are default 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   724
attribute values (as defined in <!ATTLIST> declarations.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   725
Normally, default attributes are not printed.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   726
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   727
=item * Encoding (Default: undef)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   728
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   729
Defines the output encoding (if specified.) 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   730
Note that future calls to the xml_decl() handler may override this setting
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   731
(if they contain an Encoding definition.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   732
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   733
=item * EncodeUnmapped (Default: \&XML::UM::encode_unmapped_dec)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   734
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   735
Defines how Unicode characters not found in the mapping file (of the 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   736
specified encoding) are printed. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   737
By default, they are converted to decimal entity references, like '&#123;'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   738
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   739
Use \&XML::UM::encode_unmapped_hex for hexadecimal constants, like '&#xAB;'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   740
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   741
=item * Print (Default: sub { print @_ }, which prints to stdout)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   742
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   743
The subroutine that is used to print the encoded XML output.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   744
The default prints the string to stdout.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   745
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   746
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   747
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   748
=head1 Method: get_compressed_element_suffix ($event)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   749
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   750
Override this method to support the different styles for printing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   751
empty elements in compressed notation, e.g. <p/>, <p></p>, <p />, <p>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   752
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   753
The default returns "/>", which results in <p/>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   754
Use " />" for XHTML style elements or ">" for certain HTML style elements.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   755
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   756
The $event parameter is the hash reference that was received from the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   757
start_element() handler.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   758
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   759
=head1 Extra PerlSAX event information
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   760
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   761
XML::Handler::Composer relies on hints from previous SAX filters to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   762
format certain parts of the XML. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   763
These SAX filters (e.g. XML::Filter::Reindent) pass extra information by adding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   764
name/value pairs to the appropriate PerlSAX events (the events themselves are 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   765
hash references.)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   766
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   767
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   768
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   769
=item * entity_reference: Parameter => 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   770
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   771
If Parameter is 1, it means that it is a parameter entity reference. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   772
A parameter entity is referenced with %ent; instead of &ent; and the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   773
entity declaration starts with <!ENTITY % ent ...> instead of <!ENTITY ent ...>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   774
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   775
NOTE: This should be added to the PerlSAX interface!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   776
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   777
=item * start_element/end_element: Compress => 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   778
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   779
If Compress is 1 in both the start_element and end_element event, the element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   780
will be printed in compressed form, e.g. <a/> instead of <a></a>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   781
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   782
=item * start_element: PreserveWS => 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   783
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   784
If newline conversion is active (i.e. Newline was defined in the constructor),
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   785
then newlines will *NOT* be converted in text (character events) within this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   786
element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   787
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   788
=item * attlist_decl: First, MoreFollow
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   789
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   790
The First and MoreFollow options can be used to force successive <!ATTLIST>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   791
declarations for the same element to be merged, e.g.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   792
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   793
 <!ATTLIST my_elem
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   794
        attr1 CDATA "foo"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   795
        attr2 CDATA "bar"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   796
        attr3 CDATA "quux"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   797
 >
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   798
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   799
In this example, the attlist_decl event for foo should contain
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   800
(First => 1, MoreFollow => 1) and the event for bar should contain 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   801
(MoreFollow => 1). The quux event should have no extra info.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   802
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   803
'First' indicates that the event is the first of a sequence.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   804
'MoreFollow' indicates that more events will follow in this sequence.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   805
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   806
If neither option is set by the preceding PerlSAX filter, each attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   807
definition will be printed as a separate <!ATTLIST> line.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   808
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   809
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   810
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   811
=head1 CAVEATS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   812
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   813
This code is highly experimental! 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   814
It has not been tested well and the API may change.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   815
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   816
=head1 AUTHOR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   817
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   818
Send bug reports, hints, tips, suggestions to Enno Derksen at
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   819
<F<enno@att.com>>. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   820
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   821
=cut