deprecated/buildtools/buildsystemtools/lib/XML/Parser.pod
author jascui
Wed, 17 Nov 2010 13:39:51 +0800
changeset 688 27f7c5c966fc
parent 655 3f65fd25dfd4
permissions -rw-r--r--
delete orig.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
=head1 WARNING
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
This manual page was copied from the XML::Parser distribution (version 2.27)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
written by Clark Cooper. You can find newer versions at CPAN.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
=head1 NAME
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
XML::Parser - A perl module for parsing XML documents
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
=head1 SYNOPSIS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
  use XML::Parser;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
  $p1 = new XML::Parser(Style => 'Debug');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
  $p1->parsefile('REC-xml-19980210.xml');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
  $p1->parse('<foo id="me">Hello World</foo>');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
  # Alternative
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
  $p2 = new XML::Parser(Handlers => {Start => \&handle_start,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
				     End   => \&handle_end,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
				     Char  => \&handle_char});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
  $p2->parse($socket);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
  # Another alternative
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
  $p3 = new XML::Parser(ErrorContext => 2);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
  $p3->setHandlers(Char    => \&text,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
		   Default => \&other);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
  open(FOO, 'xmlgenerator |');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
  $p3->parse(*FOO, ProtocolEncoding => 'ISO-8859-1');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
  close(FOO);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
  $p3->parsefile('junk.xml', ErrorContext => 3);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
=head1 DESCRIPTION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
This module provides ways to parse XML documents. It is built on top of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
L<XML::Parser::Expat>, which is a lower level interface to James Clark's
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
expat library. Each call to one of the parsing methods creates a new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
instance of XML::Parser::Expat which is then used to parse the document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
Expat options may be provided when the XML::Parser object is created.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
These options are then passed on to the Expat object on each parse call.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
They can also be given as extra arguments to the parse methods, in which
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
case they override options given at XML::Parser creation time.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
The behavior of the parser is controlled either by C<L</Style>> and/or
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
C<L</Handlers>> options, or by L</setHandlers> method. These all provide
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
mechanisms for XML::Parser to set the handlers needed by XML::Parser::Expat.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
If neither C<Style> nor C<Handlers> are specified, then parsing just
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
checks the document for being well-formed.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
When underlying handlers get called, they receive as their first parameter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
the I<Expat> object, not the Parser object.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
=head1 METHODS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
=item new
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
This is a class method, the constructor for XML::Parser. Options are passed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
as keyword value pairs. Recognized options are:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
=item * Style
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
This option provides an easy way to create a given style of parser. The
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
built in styles are: L<"Debug">, L<"Subs">, L<"Tree">, L<"Objects">,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
and L<"Stream">.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
Custom styles can be provided by giving a full package name containing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
at least one '::'. This package should then have subs defined for each
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
handler it wishes to have installed. See L<"STYLES"> below
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
for a discussion of each built in style.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
=item * Handlers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
When provided, this option should be an anonymous hash containing as
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
keys the type of handler and as values a sub reference to handle that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
type of event. All the handlers get passed as their 1st parameter the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
instance of expat that is parsing the document. Further details on
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
handlers can be found in L<"HANDLERS">. Any handler set here
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
overrides the corresponding handler set with the Style option.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
=item * Pkg
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
Some styles will refer to subs defined in this package. If not provided,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
it defaults to the package which called the constructor.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
=item * ErrorContext
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
This is an Expat option. When this option is defined, errors are reported
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
in context. The value should be the number of lines to show on either side
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
of the line in which the error occurred.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
=item * ProtocolEncoding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
This is an Expat option. This sets the protocol encoding name. It defaults
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
to none. The built-in encodings are: C<UTF-8>, C<ISO-8859-1>, C<UTF-16>, and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
C<US-ASCII>. Other encodings may be used if they have encoding maps in one
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
of the directories in the @Encoding_Path list. Check L<"ENCODINGS"> for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
more information on encoding maps. Setting the protocol encoding overrides
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
any encoding in the XML declaration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
=item * Namespaces
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
This is an Expat option. If this is set to a true value, then namespace
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
processing is done during the parse. See L<XML::Parser::Expat/"Namespaces">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
for further discussion of namespace processing.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
=item * NoExpand
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
This is an Expat option. Normally, the parser will try to expand references
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
to entities defined in the internal subset. If this option is set to a true
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
value, and a default handler is also set, then the default handler will be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
called when an entity reference is seen in text. This has no effect if a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
default handler has not been registered, and it has no effect on the expansion
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
of entity references inside attribute values.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
=item * Stream_Delimiter
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
This is an Expat option. It takes a string value. When this string is found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
alone on a line while parsing from a stream, then the parse is ended as if it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
saw an end of file. The intended use is with a stream of xml documents in a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
MIME multipart format. The string should not contain a trailing newline.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
=item * ParseParamEnt
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
This is an Expat option. Unless standalone is set to "yes" in the XML
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
declaration, setting this to a true value allows the external DTD to be read,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
and parameter entities to be parsed and expanded.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
=item * Non-Expat-Options
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
If provided, this should be an anonymous hash whose keys are options that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
shouldn't be passed to Expat. This should only be of concern to those
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
subclassing XML::Parser.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
=item  setHandlers(TYPE, HANDLER [, TYPE, HANDLER [...]])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
This method registers handlers for various parser events. It overrides any
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
previous handlers registered through the Style or Handler options or through
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
earlier calls to setHandlers. By providing a false or undefined value as
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
the handler, the existing handler can be unset.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
This method returns a list of type, handler pairs corresponding to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
input. The handlers returned are the ones that were in effect prior to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
the call.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
See a description of the handler types in L<"HANDLERS">.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
=item parse(SOURCE [, OPT => OPT_VALUE [...]])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
The SOURCE parameter should either be a string containing the whole XML
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
document, or it should be an open IO::Handle. Constructor options to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
XML::Parser::Expat given as keyword-value pairs may follow the SOURCE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
parameter. These override, for this call, any options or attributes passed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
through from the XML::Parser instance.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
A die call is thrown if a parse error occurs. Otherwise it will return 1
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
or whatever is returned from the B<Final> handler, if one is installed.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
In other words, what parse may return depends on the style.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
=item parsestring
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
This is just an alias for parse for backwards compatibility.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
=item parsefile(FILE [, OPT => OPT_VALUE [...]])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
Open FILE for reading, then call parse with the open handle. The file
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
is closed no matter how parse returns. Returns what parse returns.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
=item parse_start([ OPT => OPT_VALUE [...]])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
Create and return a new instance of XML::Parser::ExpatNB. Constructor
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
options may be provided. If an init handler has been provided, it is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
called before returning the ExpatNB object. Documents are parsed by
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
making incremental calls to the parse_more method of this object, which
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
takes a string. A single call to the parse_done method of this object,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
which takes no arguments, indicates that the document is finished.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
If there is a final handler installed, it is executed by the parse_done
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
method before returning and the parse_done method returns whatever is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
returned by the final handler.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
=head1 HANDLERS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
Expat is an event based parser. As the parser recognizes parts of the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
document (say the start or end tag for an XML element), then any handlers
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
registered for that type of an event are called with suitable parameters.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
All handlers receive an instance of XML::Parser::Expat as their first
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
argument. See L<XML::Parser::Expat/"METHODS"> for a discussion of the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
methods that can be called on this object.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
=head2 Init		(Expat)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
This is called just before the parsing of the document starts.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
=head2 Final		(Expat)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
This is called just after parsing has finished, but only if no errors
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
occurred during the parse. Parse returns what this returns.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
=head2 Start		(Expat, Element [, Attr, Val [,...]])
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
This event is generated when an XML start tag is recognized. Element is the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
name of the XML element type that is opened with the start tag. The Attr &
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
Val pairs are generated for each attribute in the start tag.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
=head2 End		(Expat, Element)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
This event is generated when an XML end tag is recognized. Note that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
an XML empty tag (<foo/>) generates both a start and an end event.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
=head2 Char		(Expat, String)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
This event is generated when non-markup is recognized. The non-markup
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
sequence of characters is in String. A single non-markup sequence of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
characters may generate multiple calls to this handler. Whatever the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
encoding of the string in the original document, this is given to the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
handler in UTF-8.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
=head2 Proc		(Expat, Target, Data)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
This event is generated when a processing instruction is recognized.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
=head2 Comment		(Expat, Data)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
This event is generated when a comment is recognized.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
=head2 CdataStart	(Expat)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
This is called at the start of a CDATA section.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
=head2 CdataEnd		(Expat)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
This is called at the end of a CDATA section.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
=head2 Default		(Expat, String)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
This is called for any characters that don't have a registered handler.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
This includes both characters that are part of markup for which no
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
events are generated (markup declarations) and characters that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
could generate events, but for which no handler has been registered.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
Whatever the encoding in the original document, the string is returned to
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
the handler in UTF-8.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
=head2 Unparsed		(Expat, Entity, Base, Sysid, Pubid, Notation)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
This is called for a declaration of an unparsed entity. Entity is the name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
of the entity. Base is the base to be used for resolving a relative URI.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
Sysid is the system id. Pubid is the public id. Notation is the notation
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
name. Base and Pubid may be undefined.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
=head2 Notation		(Expat, Notation, Base, Sysid, Pubid)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
This is called for a declaration of notation. Notation is the notation name.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
Base is the base to be used for resolving a relative URI. Sysid is the system
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
id. Pubid is the public id. Base, Sysid, and Pubid may all be undefined.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
=head2 ExternEnt	(Expat, Base, Sysid, Pubid)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
This is called when an external entity is referenced. Base is the base to be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
used for resolving a relative URI. Sysid is the system id. Pubid is the public
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
id. Base, and Pubid may be undefined.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
This handler should either return a string, which represents the contents of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
the external entity, or return an open filehandle that can be read to obtain
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
the contents of the external entity, or return undef, which indicates the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
external entity couldn't be found and will generate a parse error.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
If an open filehandle is returned, it must be returned as either a glob
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
(*FOO) or as a reference to a glob (e.g. an instance of IO::Handle). The
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
parser will close the filehandle after using it.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
A default handler, XML::Parser::default_ext_ent_handler, is installed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
for this. It only handles the file URL method and it assumes "file:" if
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
it isn't there. The expat base method can be used to set a basename for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
relative pathnames. If no basename is given, or if the basename is itself
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
a relative name, then it is relative to the current working directory.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
=head2 Entity		(Expat, Name, Val, Sysid, Pubid, Ndata)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
This is called when an entity is declared. For internal entities, the Val
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
parameter will contain the value and the remaining three parameters will be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
undefined. For external entities, the Val parameter will be undefined, the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
Sysid parameter will have the system id, the Pubid parameter will have the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
public id if it was provided (it will be undefined otherwise), the Ndata
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
parameter will contain the notation for unparsed entities. If this is a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
parameter entity declaration, then a '%' will be prefixed to the name.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
Note that this handler and the Unparsed handler above overlap. If both are
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
set, then this handler will not be called for unparsed entities.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
=head2 Element		(Expat, Name, Model)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
The element handler is called when an element declaration is found. Name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
is the element name, and Model is the content model as a string.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
=head2 Attlist		(Expat, Elname, Attname, Type, Default, Fixed)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
This handler is called for each attribute in an ATTLIST declaration.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
So an ATTLIST declaration that has multiple attributes will generate multiple
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
calls to this handler. The Elname parameter is the name of the element with
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
which the attribute is being associated. The Attname parameter is the name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
of the attribute. Type is the attribute type, given as a string. Default is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
the default value, which will either be "#REQUIRED", "#IMPLIED" or a quoted
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
string (i.e. the returned string will begin and end with a quote character).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
If Fixed is true, then this is a fixed attribute.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
=head2 Doctype		(Expat, Name, Sysid, Pubid, Internal)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
This handler is called for DOCTYPE declarations. Name is the document type
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
name. Sysid is the system id of the document type, if it was provided,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
otherwise it's undefined. Pubid is the public id of the document type,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
which will be undefined if no public id was given. Internal is the internal
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
subset, given as a string. If there was no internal subset, it will be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
undefined. Internal will contain all whitespace, comments, processing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
instructions, and declarations seen in the internal subset. The declarations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
will be there whether or not they have been processed by another handler
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
(except for unparsed entities processed by the Unparsed handler). However,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
comments and processing instructions will not appear if they've been processed
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
by their respective handlers.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
=head2 XMLDecl		(Expat, Version, Encoding, Standalone)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
This handler is called for xml declarations. Version is a string containg
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
the version. Encoding is either undefined or contains an encoding string.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
Standalone will be either true, false, or undefined if the standalone attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
is yes, no, or not made respectively.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
=head1 STYLES
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
=head2 Debug
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
This just prints out the document in outline form. Nothing special is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
returned by parse.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
=head2 Subs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
Each time an element starts, a sub by that name in the package specified
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
by the Pkg option is called with the same parameters that the Start
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
handler gets called with.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
Each time an element ends, a sub with that name appended with an underscore
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
("_"), is called with the same parameters that the End handler gets called
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
with.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
Nothing special is returned by parse.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
=head2 Tree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
Parse will return a parse tree for the document. Each node in the tree
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
takes the form of a tag, content pair. Text nodes are represented with
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
a pseudo-tag of "0" and the string that is their content. For elements,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
the content is an array reference. The first item in the array is a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
(possibly empty) hash reference containing attributes. The remainder of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
the array is a sequence of tag-content pairs representing the content
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
of the element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
So for example the result of parsing:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
  <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
would be:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
             Tag   Content
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
  ==================================================================
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
  [foo, [{}, head, [{id => "a"}, 0, "Hello ",  em, [{}, 0, "there"]],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
	      bar, [         {}, 0, "Howdy",  ref, [{}]],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
	        0, "do"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
	]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
  ]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
The root document "foo", has 3 children: a "head" element, a "bar"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
element and the text "do". After the empty attribute hash, these are
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
represented in it's contents by 3 tag-content pairs.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
=head2 Objects
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
This is similar to the Tree style, except that a hash object is created for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
each element. The corresponding object will be in the class whose name
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
is created by appending "::" and the element name to the package set with
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
the Pkg option. Non-markup text will be in the ::Characters class. The
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
contents of the corresponding object will be in an anonymous array that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
is the value of the Kids property for that object.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
=head2 Stream
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
This style also uses the Pkg package. If none of the subs that this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
style looks for is there, then the effect of parsing with this style is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
to print a canonical copy of the document without comments or declarations.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
All the subs receive as their 1st parameter the Expat instance for the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
document they're parsing.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
It looks for the following routines:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
=item * StartDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
Called at the start of the parse .
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
=item * StartTag
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
Called for every start tag with a second parameter of the element type. The $_
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
variable will contain a copy of the tag and the %_ variable will contain
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
attribute values supplied for that element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
=item * EndTag
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
Called for every end tag with a second parameter of the element type. The $_
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
variable will contain a copy of the end tag.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
=item * Text
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
Called just before start or end tags with accumulated non-markup text in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
the $_ variable.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
=item * PI
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
Called for processing instructions. The $_ variable will contain a copy of
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
the PI and the target and data are sent as 2nd and 3rd parameters
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
respectively.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
=item * EndDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
Called at conclusion of the parse.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
=head1 ENCODINGS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
XML documents may be encoded in character sets other than Unicode as
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
long as they may be mapped into the Unicode character set. Expat has
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
further restrictions on encodings. Read the xmlparse.h header file in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
the expat distribution to see details on these restrictions.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
Expat has built-in encodings for: C<UTF-8>, C<ISO-8859-1>, C<UTF-16>, and
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
C<US-ASCII>. Encodings are set either through the XML declaration
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
encoding attribute or through the ProtocolEncoding option to XML::Parser
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
or XML::Parser::Expat.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
For encodings other than the built-ins, expat calls the function
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
load_encoding in the Expat package with the encoding name. This function
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
looks for a file in the path list @XML::Parser::Expat::Encoding_Path, that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
matches the lower-cased name with a '.enc' extension. The first one it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
finds, it loads.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
If you wish to build your own encoding maps, check out the XML::Encoding
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
module from CPAN.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
=head1 AUTHORS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
Larry Wall <F<larry@wall.org>> wrote version 1.0.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
Clark Cooper <F<coopercc@netheaven.com>> picked up support, changed the API
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
for this version (2.x), provided documentation,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
and added some standard package features.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
=cut