XML::Parser Methods

The following methods are defined by XML::Parser.

new

new(%option) 

Constructor. Options are passed as keyword/value pairs. Recognized options are:

  • Style
  • Sets the type of parser. The built-in styles are Debug, Subs, Tree, Objects, and Stream. Custom styles can be provided by giving a fully qualified package name containing at least one "::". This package must have subroutines defined for each parser type.
  • Handlers
  • An anonymous hash containing the handler types as the keys with their associated values, which are references to subroutines for handling that type of event.
  • Pkg
  • Some styles will refer to subroutines defined in the specified package.
  • ErrorContext
  • The number of lines to show surrounding the line in which an error occurred.
  • ProtocolEncoding
  • Sets the protocol-encoding name (default is none). The built-in encodings are UTF-8, ISO-8859-1, UTF-16, and US-ASCII. You may introduce additional encodings by adding directories to @Encoding_Path.
  • Namespaces
  • If true, then namespace processing is done during the parse.
  • NoExpand
  • Normally, the parser will try to expand references to entities defined internally. If this option is true and a default handler is also set, then the default handler will be called when an entity reference is encountered.
  • Stream_Delimiter
  • A string for XML::Parser to interpret as end-of-file if found alone on a line. Useful when working with MIME multipart documents. The string should not contain a trailing newline.
  • ParseParamEnt
  • Unless standalone is set to yes in the XML declaration, setting this to true allows the external DTD to be read, and parameter entities to be parsed and expanded.
  • NoLWP
  • If true, forces the use of a file-based external entity handler.
  • Non-Expat-Options
  • An anonymous hash whose keys are options that shouldn't be passed to Expat. This should be a concern only for those subclassing XML::Parser.
parse

parse(source [, opt => opt_value [...]]) 

Parses the document. The source parameter should be either a string containing the entire XML document or an open IO::Handle. Options given as keyword/value pairs may follow the source parameter and will override any options or attributes passed from the XML::Parser instance.

parse exits with die if a parse error occurs or returns with success.

parsefile

parsefile(file [, opt => opt_value [...]]) 

Opens file for reading, then calls parse with the open handle. The file is closed no matter what parse returns. Returns what parse returns.

parse_start

parse_start([ opt => opt_value [...]]) 

Creates and returns a new instance of XML::Parser::ExpatNB. If an init handler is specified, it is called before returning the ExpatNB object. Documents are parsed with incremental calls to the parse_more. A single call to the parse_done method of this object indicates that the document is finished. The parse_done method returns whatever is returned by the final handler.

parsestring

parsestring 

An alias for parse, for backwards compatibility.

setHandlers

setHandlers(type, handler [, type, handler [...]]) 

Registers handlers for various parser events. setHandlers overrides any previous handlers set in Style or Handler options or through earlier calls to setHandlers. Returns a list of type and handler pairs.