?? module-xmllib.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>13.9 xmllib -- A parser for XML documents</title>
<META NAME="description" CONTENT="13.9 xmllib -- A parser for XML documents">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="module-xml.sax.xmlreader.html" tppabs="http://www.python.org/doc/current/lib/module-xml.sax.xmlreader.html">
<LINK REL="up" href="markup.html" tppabs="http://www.python.org/doc/current/lib/markup.html">
<LINK REL="next" href="xml-namespace.html" tppabs="http://www.python.org/doc/current/lib/xml-namespace.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="attributes-ns-impl-objects.html" tppabs="http://www.python.org/doc/current/lib/attributes-ns-impl-objects.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="markup.html" tppabs="http://www.python.org/doc/current/lib/markup.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="xml-namespace.html" tppabs="http://www.python.org/doc/current/lib/xml-namespace.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="attributes-ns-impl-objects.html" tppabs="http://www.python.org/doc/current/lib/attributes-ns-impl-objects.html">13.8.6 AttributesNSImpl Objects</A>
<b class="navlabel">Up:</b> <a class="sectref" href="markup.html" tppabs="http://www.python.org/doc/current/lib/markup.html">13. Structured Markup Processing</A>
<b class="navlabel">Next:</b> <a class="sectref" href="xml-namespace.html" tppabs="http://www.python.org/doc/current/lib/xml-namespace.html">13.9.1 XML Namespaces</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0015900000000000000000">
13.9 <tt class="module">xmllib</tt> --
A parser for XML documents</A>
</H1>
<P>
<P>
<P>
<b>Deprecated since release 2.0.</b>
Use <tt class='module'><a href="module-xml.sax.html" tppabs="http://www.python.org/doc/current/lib/module-xml.sax.html">xml.sax</a></tt> instead. The newer XML
package includes full support for XML 1.0.<p>
<P>
Changed in version 1.5.2:
.
<P>
This module defines a class <tt class="class">XMLParser</tt> which serves as the basis
for parsing text files formatted in XML (Extensible Markup Language).
<P>
<dl><dt><b><a name='l2h-2734'><tt class='class'>XMLParser</tt></a></b> ()
<dd>
The <tt class="class">XMLParser</tt> class must be instantiated without
arguments.<A NAME="tex2html58"
HREF="#foot32466"><SUP>13.1</SUP></A></dl>
<P>
This class provides the following interface methods and instance variables:
<P>
<dl><dt><b><a name='l2h-2735'><tt class='member'>attributes</tt></a></b>
<dd>
A mapping of element names to mappings. The latter mapping maps
attribute names that are valid for the element to the default value of
the attribute, or if there is no default to <code>None</code>. The default
value is the empty dictionary. This variable is meant to be
overridden, not extended since the default is shared by all instances
of <tt class="class">XMLParser</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-2736'><tt class='member'>elements</tt></a></b>
<dd>
A mapping of element names to tuples. The tuples contain a function
for handling the start and end tag respectively of the element, or
<code>None</code> if the method <tt class="method">unknown_starttag()</tt> or
<tt class="method">unknown_endtag()</tt> is to be called. The default value is the
empty dictionary. This variable is meant to be overridden, not
extended since the default is shared by all instances of
<tt class="class">XMLParser</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-2737'><tt class='member'>entitydefs</tt></a></b>
<dd>
A mapping of entitynames to their values. The default value contains
definitions for <code>'lt'</code>, <code>'gt'</code>, <code>'amp'</code>, <code>'quot'</code>,
and <code>'apos'</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-2738'><tt class='method'>reset</tt></a></b> ()
<dd>
Reset the instance. Loses all unprocessed data. This is called
implicitly at the instantiation time.
</dl>
<P>
<dl><dt><b><a name='l2h-2739'><tt class='method'>setnomoretags</tt></a></b> ()
<dd>
Stop processing tags. Treat all following input as literal input
(CDATA).
</dl>
<P>
<dl><dt><b><a name='l2h-2740'><tt class='method'>setliteral</tt></a></b> ()
<dd>
Enter literal mode (CDATA mode). This mode is automatically exited
when the close tag matching the last unclosed open tag is encountered.
</dl>
<P>
<dl><dt><b><a name='l2h-2741'><tt class='method'>feed</tt></a></b> (<var>data</var>)
<dd>
Feed some text to the parser. It is processed insofar as it consists
of complete tags; incomplete data is buffered until more data is
fed or <tt class="method">close()</tt> is called.
</dl>
<P>
<dl><dt><b><a name='l2h-2742'><tt class='method'>close</tt></a></b> ()
<dd>
Force processing of all buffered data as if it were followed by an
end-of-file mark. This method may be redefined by a derived class to
define additional processing at the end of the input, but the
redefined version should always call <tt class="method">close()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-2743'><tt class='method'>translate_references</tt></a></b> (<var>data</var>)
<dd>
Translate all entity and character references in <var>data</var> and
return the translated string.
</dl>
<P>
<dl><dt><b><a name='l2h-2744'><tt class='method'>getnamespace</tt></a></b> ()
<dd>
Return a mapping of namespace abbreviations to namespace URIs that are
currently in effect.
</dl>
<P>
<dl><dt><b><a name='l2h-2745'><tt class='method'>handle_xml</tt></a></b> (<var>encoding, standalone</var>)
<dd>
This method is called when the "<tt class="samp"><?xml ...?></tt>" tag is processed.
The arguments are the values of the encoding and standalone attributes
in the tag. Both encoding and standalone are optional. The values
passed to <tt class="method">handle_xml()</tt> default to <code>None</code> and the string
<code>'no'</code> respectively.
</dl>
<P>
<dl><dt><b><a name='l2h-2746'><tt class='method'>handle_doctype</tt></a></b> (<var>tag, pubid, syslit, data</var>)
<dd>
This method is called when the
"<tt class="samp"><!DOCTYPE...></tt>" declaration is processed. The arguments are the
tag name of the root element, the Formal Public Identifier (or <code>None</code> if not specified), the system
identifier, and the uninterpreted contents of the internal DTD subset
as a string (or <code>None</code> if not present).
</dl>
<P>
<dl><dt><b><a name='l2h-2747'><tt class='method'>handle_starttag</tt></a></b> (<var>tag, method, attributes</var>)
<dd>
This method is called to handle start tags for which a start tag
handler is defined in the instance variable <tt class="member">elements</tt>. The
<var>tag</var> argument is the name of the tag, and the
<var>method</var> argument is the function (method) which should be used to
support semantic interpretation of the start tag. The
<var>attributes</var> argument is a dictionary of attributes, the key being
the <var>name</var> and the value being the <var>value</var> of the attribute
found inside the tag's <code><></code> brackets. Character and entity
references in the <var>value</var> have been interpreted. For instance,
for the start tag <code><A HREF="http://www.cwi.nl/"></code>, this method
would be called as <code>handle_starttag('A', self.elements['A'][0],
{'HREF': 'http://www.cwi.nl/'})</code>. The base implementation simply
calls <var>method</var> with <var>attributes</var> as the only argument.
</dl>
<P>
<dl><dt><b><a name='l2h-2748'><tt class='method'>handle_endtag</tt></a></b> (<var>tag, method</var>)
<dd>
This method is called to handle endtags for which an end tag handler
is defined in the instance variable <tt class="member">elements</tt>. The <var>tag</var>
argument is the name of the tag, and the <var>method</var> argument is the
function (method) which should be used to support semantic
interpretation of the end tag. For instance, for the endtag
<code></A></code>, this method would be called as <code>handle_endtag('A',
self.elements['A'][1])</code>. The base implementation simply calls
<var>method</var>.
</dl>
<P>
<dl><dt><b><a name='l2h-2749'><tt class='method'>handle_data</tt></a></b> (<var>data</var>)
<dd>
This method is called to process arbitrary data. It is intended to be
overridden by a derived class; the base class implementation does
nothing.
</dl>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -