MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/local/ssl/share/doc/python-docs-2.4.3/html/lib/content-handler-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="dtd-handler-objects.html" />
<link rel="prev" href="module-xml.sax.handler.html" />
<link rel="parent" href="module-xml.sax.handler.html" />
<link rel="next" href="dtd-handler-objects.html" />
<meta name='aesop' content='information' />
<title>13.10.1 ContentHandler Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="13.10 xml.sax.handler  "
  href="module-xml.sax.handler.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="13.10 xml.sax.handler  "
  href="module-xml.sax.handler.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="13.10.2 DTDHandler Objects"
  href="dtd-handler-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-xml.sax.handler.html">13.10 xml.sax.handler  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xml.sax.handler.html">13.10 xml.sax.handler  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="dtd-handler-objects.html">13.10.2 DTDHandler Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00151010000000000000000"></A><A NAME="content-handler-objects"></A>
<BR>
13.10.1 ContentHandler Objects 
</H2>

<P>
Users are expected to subclass <tt class="class">ContentHandler</tt> to support their
application.  The following methods are called by the parser on the
appropriate events in the input document:

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4489' xml:id='l2h-4489' class="method">setDocumentLocator</tt></b>(</nobr></td>
  <td><var>locator</var>)</td></tr></table></dt>
<dd>
  Called by the parser to give the application a locator for locating
  the origin of document events.

<P>
SAX parsers are strongly encouraged (though not absolutely required)
  to supply a locator: if it does so, it must supply the locator to
  the application by invoking this method before invoking any of the
  other methods in the DocumentHandler interface.

<P>
The locator allows the application to determine the end position of
  any document-related event, even if the parser is not reporting an
  error. Typically, the application will use this information for
  reporting its own errors (such as character content that does not
  match an application's business rules). The information returned by
  the locator is probably not sufficient for use with a search engine.

<P>
Note that the locator will return correct information only during
  the invocation of the events in this interface. The application
  should not attempt to use it at any other time.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4490' xml:id='l2h-4490' class="method">startDocument</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Receive notification of the beginning of a document.

<P>
The SAX parser will invoke this method only once, before any other
  methods in this interface or in DTDHandler (except for
  <tt class="method">setDocumentLocator()</tt>).
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4491' xml:id='l2h-4491' class="method">endDocument</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Receive notification of the end of a document.

<P>
The SAX parser will invoke this method only once, and it will be the
  last method invoked during the parse. The parser shall not invoke
  this method until it has either abandoned parsing (because of an
  unrecoverable error) or reached the end of input.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4492' xml:id='l2h-4492' class="method">startPrefixMapping</tt></b>(</nobr></td>
  <td><var>prefix, uri</var>)</td></tr></table></dt>
<dd>
  Begin the scope of a prefix-URI Namespace mapping.

<P>
The information from this event is not necessary for normal
  Namespace processing: the SAX XML reader will automatically replace
  prefixes for element and attribute names when the
  <code>feature_namespaces</code> feature is enabled (the default).

<P>
There are cases, however, when applications need to use prefixes in
  character data or in attribute values, where they cannot safely be
  expanded automatically; the <tt class="method">startPrefixMapping()</tt> and
  <tt class="method">endPrefixMapping()</tt> events supply the information to the
  application to expand prefixes in those contexts itself, if
  necessary.

<P>
Note that <tt class="method">startPrefixMapping()</tt> and
  <tt class="method">endPrefixMapping()</tt> events are not guaranteed to be properly
  nested relative to each-other: all <tt class="method">startPrefixMapping()</tt>
  events will occur before the corresponding <tt class="method">startElement()</tt>
  event, and all <tt class="method">endPrefixMapping()</tt> events will occur after
  the corresponding <tt class="method">endElement()</tt> event, but their order is
  not guaranteed.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4493' xml:id='l2h-4493' class="method">endPrefixMapping</tt></b>(</nobr></td>
  <td><var>prefix</var>)</td></tr></table></dt>
<dd>
  End the scope of a prefix-URI mapping.

<P>
See <tt class="method">startPrefixMapping()</tt> for details. This event will
  always occur after the corresponding <tt class="method">endElement()</tt> event,
  but the order of <tt class="method">endPrefixMapping()</tt> events is not otherwise
  guaranteed.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4494' xml:id='l2h-4494' class="method">startElement</tt></b>(</nobr></td>
  <td><var>name, attrs</var>)</td></tr></table></dt>
<dd>
  Signals the start of an element in non-namespace mode.

<P>
The <var>name</var> parameter contains the raw XML 1.0 name of the
  element type as a string and the <var>attrs</var> parameter holds an
  object of the <a class="ulink" href="attributes-objects.html"
  ><tt class="class">Attributes</tt>
  interface</a> containing the attributes of the
  element.  The object passed as <var>attrs</var> may be re-used by the
  parser; holding on to a reference to it is not a reliable way to
  keep a copy of the attributes.  To keep a copy of the attributes,
  use the <tt class="method">copy()</tt> method of the <var>attrs</var> object.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4495' xml:id='l2h-4495' class="method">endElement</tt></b>(</nobr></td>
  <td><var>name</var>)</td></tr></table></dt>
<dd>
  Signals the end of an element in non-namespace mode.

<P>
The <var>name</var> parameter contains the name of the element type, just
  as with the <tt class="method">startElement()</tt> event.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4496' xml:id='l2h-4496' class="method">startElementNS</tt></b>(</nobr></td>
  <td><var>name, qname, attrs</var>)</td></tr></table></dt>
<dd>
  Signals the start of an element in namespace mode.

<P>
The <var>name</var> parameter contains the name of the element type as a
  <code>(<var>uri</var>, <var>localname</var>)</code> tuple, the <var>qname</var> parameter
  contains the raw XML 1.0 name used in the source document, and the
  <var>attrs</var> parameter holds an instance of the
  <a class="ulink" href="attributes-ns-objects.html"
  ><tt class="class">AttributesNS</tt> interface</a>
  containing the attributes of the element.  If no namespace is
  associated with the element, the <var>uri</var> component of <var>name</var>
  will be <code>None</code>.  The object passed as <var>attrs</var> may be
  re-used by the parser; holding on to a reference to it is not a
  reliable way to keep a copy of the attributes.  To keep a copy of
  the attributes, use the <tt class="method">copy()</tt> method of the <var>attrs</var>
  object.

<P>
Parsers may set the <var>qname</var> parameter to <code>None</code>, unless the
  <code>feature_namespace_prefixes</code> feature is activated.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4497' xml:id='l2h-4497' class="method">endElementNS</tt></b>(</nobr></td>
  <td><var>name, qname</var>)</td></tr></table></dt>
<dd>
  Signals the end of an element in namespace mode.

<P>
The <var>name</var> parameter contains the name of the element type, just
  as with the <tt class="method">startElementNS()</tt> method, likewise the
  <var>qname</var> parameter.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4498' xml:id='l2h-4498' class="method">characters</tt></b>(</nobr></td>
  <td><var>content</var>)</td></tr></table></dt>
<dd>
  Receive notification of character data.

<P>
The Parser will call this method to report each chunk of character
  data. SAX parsers may return all contiguous character data in a
  single chunk, or they may split it into several chunks; however, all
  of the characters in any single event must come from the same
  external entity so that the Locator provides useful information.

<P>
<var>content</var> may be a Unicode string or a byte string; the
  <code>expat</code> reader module produces always Unicode strings.

<P>
<span class="note"><b class="label">Note:</b>
The earlier SAX 1 interface provided by the Python
  XML Special Interest Group used a more Java-like interface for this
  method.  Since most parsers used from Python did not take advantage
  of the older interface, the simpler signature was chosen to replace
  it.  To convert old code to the new interface, use <var>content</var>
  instead of slicing content with the old <var>offset</var> and
  <var>length</var> parameters.</span>
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4499' xml:id='l2h-4499' class="method">ignorableWhitespace</tt></b>(</nobr></td>
  <td><var>whitespace</var>)</td></tr></table></dt>
<dd>
  Receive notification of ignorable whitespace in element content.

<P>
Validating Parsers must use this method to report each chunk
  of ignorable whitespace (see the W3C XML 1.0 recommendation,
  section 2.10): non-validating parsers may also use this method
  if they are capable of parsing and using content models.

<P>
SAX parsers may return all contiguous whitespace in a single
  chunk, or they may split it into several chunks; however, all
  of the characters in any single event must come from the same
  external entity, so that the Locator provides useful
  information.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4500' xml:id='l2h-4500' class="method">processingInstruction</tt></b>(</nobr></td>
  <td><var>target, data</var>)</td></tr></table></dt>
<dd>
  Receive notification of a processing instruction.

<P>
The Parser will invoke this method once for each processing
  instruction found: note that processing instructions may occur
  before or after the main document element.

<P>
A SAX parser should never report an XML declaration (XML 1.0,
  section 2.8) or a text declaration (XML 1.0, section 4.3.1) using
  this method.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4501' xml:id='l2h-4501' class="method">skippedEntity</tt></b>(</nobr></td>
  <td><var>name</var>)</td></tr></table></dt>
<dd>
  Receive notification of a skipped entity.

<P>
The Parser will invoke this method once for each entity
  skipped. Non-validating processors may skip entities if they have
  not seen the declarations (because, for example, the entity was
  declared in an external DTD subset). All processors may skip
  external entities, depending on the values of the
  <code>feature_external_ges</code> and the
  <code>feature_external_pes</code> properties.
</dl>

<P>

<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="13.10 xml.sax.handler  "
  href="module-xml.sax.handler.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="13.10 xml.sax.handler  "
  href="module-xml.sax.handler.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="13.10.2 DTDHandler Objects"
  href="dtd-handler-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-xml.sax.handler.html">13.10 xml.sax.handler  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xml.sax.handler.html">13.10 xml.sax.handler  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="dtd-handler-objects.html">13.10.2 DTDHandler Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.3, documentation updated on 29 March 2006.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>