XML::SAX2Perl −− translate Java/CORBA style SAX methods to Perl methods


 use XML::SAX2Perl;
 $sax2perl = XML::SAX2Perl(Handler => $my_handler);


"XML::SAX2Perl" is a SAX filter that translates Java/CORBA style SAX methods to Perl style method calls. This man page summarizes the specific options, handlers, and properties supported by "XML::SAX2Perl"; please refer to the Perl SAX standard "XML::SAX" for general usage information.



Creates a new parser object. Default options for parsing, described below, are passed as key-value pairs or as a single hash. Options may be changed directly in the parser object unless stated otherwise. Options passed to ‘"parse()"’ override the default options in the parser object for the duration of the parse.


Parses a document. Options, described below, are passed as key-value pairs or as a single hash. Options passed to ‘"parse()"’ override default options in the parser object.


Returns the location as a hash:

  ColumnNumber    The column number of the parse.
  LineNumber      The line number of the parse.
  PublicId        A string containing the public identifier, or undef
                  if none is available.
  SystemId        A string containing the system identifier, or undef
                  if none is available.

SAX DocumentHandler Methods

The following methods are DocumentHandler methods that the SAX 1.0 parser will call and "XML::SAX2Perl" will translate to Perl SAX methods calls. See SAX 1.0 for details.

 startElement(name, atts)
 characters(ch, start, length)
 ignorableWhitespace(ch, start, length)
 processingInstruction(target, data)


The following options are supported by "XML::SAX2Perl":

 Handler          default handler to receive events
 DocumentHandler  handler to receive document events
 DTDHandler       handler to receive DTD events
 ErrorHandler     handler to receive error events
 EntityResolver   handler to resolve entities
 Locale           locale to provide localisation for errors
 Source           hash containing the input source for parsing

If no handlers are provided then all events will be silently ignored, except for ‘"fatal_error()"’ which will cause a ‘"die()"’ to be called after calling ‘"end_document()"’.

If a single string argument is passed to the ‘"parse()"’ method, it is treated as if a ‘"Source"’ option was given with a ‘"String"’ parameter.

The ‘"Source"’ hash may contain the following parameters:

 ByteStream       The raw byte stream (file handle) containing the
 String           A string containing the document.
 SystemId         The system identifier (URI) of the document.
 PublicId         The public identifier.
 Encoding         A string describing the character encoding.

If more than one of ‘"ByteStream"’, ‘"String"’, or ‘"SystemId"’, then preference is given first to ‘"ByteStream"’, then ‘"String"’, then ‘"SystemId"’.


The following handlers and properties are supported by "XML::SAX2Perl":

DocumentHandler methods

Receive notification of the beginning of a document.

 Locator          An object that can return the location of any SAX
                  document event.


Receive notification of the end of a document.

No properties defined.


Receive notification of the beginning of an element.

 Name             The element type name.
 Attributes       Attributes attached to the element, if any.

ALPHA WARNING: The ‘"Attributes"’ value is not translated from the SAX 1.0 value, so it will contain an AttributeList object.


Receive notification of the end of an element.

 Name             The element type name.


Receive notification of character data.

 Data             The characters from the XML document.


Receive notification of ignorable whitespace in element content.

 Data             The characters from the XML document.


Receive notification of a processing instruction.

 Target           The processing instruction target.
 Data             The processing instruction data, if any.


Ken MacLeod <ken@bitsko.slc.ut.us>


perl(1), XML::Perl2SAX(3).

 Extensible Markup Language (XML) <http://www.w3c.org/XML/>
 Simple API for XML (SAX) <http://www.megginson.com/SAX/>


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.