Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-xml.dom.html" /> | |
13 | <link rel="prev" href="module-htmlentitydefs.html" /> | |
14 | <link rel="parent" href="markup.html" /> | |
15 | <link rel="next" href="xmlparser-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>13.5 xml.parsers.expat -- Fast XML parsing using Expat</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="13.4 htmlentitydefs " | |
25 | href="module-htmlentitydefs.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="13. Structured Markup Processing" | |
28 | href="markup.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="13.5.1 XMLParser Objects" | |
31 | href="xmlparser-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-htmlentitydefs.html">13.4 htmlentitydefs </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="xmlparser-objects.html">13.5.1 XMLParser Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0015500000000000000000"> | |
56 | 13.5 <tt class="module">xml.parsers.expat</tt> -- | |
57 | Fast XML parsing using Expat</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-xml.parsers.expat"></A> | |
62 | ||
63 | <P> | |
64 | ||
65 | <span class="versionnote">New in version 2.0.</span> | |
66 | ||
67 | <P> | |
68 | The <tt class="module">xml.parsers.expat</tt> module is a Python interface to the | |
69 | Expat<a id='l2h-4306' xml:id='l2h-4306'></a> non-validating XML parser. | |
70 | The module provides a single extension type, <tt class="class">xmlparser</tt>, that | |
71 | represents the current state of an XML parser. After an | |
72 | <tt class="class">xmlparser</tt> object has been created, various attributes of the object | |
73 | can be set to handler functions. When an XML document is then fed to | |
74 | the parser, the handler functions are called for the character data | |
75 | and markup in the XML document. | |
76 | ||
77 | <P> | |
78 | This module uses the <tt class="module">pyexpat</tt><a id='l2h-4307' xml:id='l2h-4307'></a> module to | |
79 | provide access to the Expat parser. Direct use of the | |
80 | <tt class="module">pyexpat</tt> module is deprecated. | |
81 | ||
82 | <P> | |
83 | This module provides one exception and one type object: | |
84 | ||
85 | <P> | |
86 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4301' xml:id='l2h-4301' class="exception">ExpatError</tt></b></dt> | |
87 | <dd> | |
88 | The exception raised when Expat reports an error. See section | |
89 | <A href="expaterror-objects.html#expaterror-objects">13.5.2</A>, ``ExpatError Exceptions,'' for more | |
90 | information on interpreting Expat errors. | |
91 | </dd></dl> | |
92 | ||
93 | <P> | |
94 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4302' xml:id='l2h-4302' class="exception">error</tt></b></dt> | |
95 | <dd> | |
96 | Alias for <tt class="exception">ExpatError</tt>. | |
97 | </dd></dl> | |
98 | ||
99 | <P> | |
100 | <dl><dt><b><tt id='l2h-4303' xml:id='l2h-4303'>XMLParserType</tt></b></dt> | |
101 | <dd> | |
102 | The type of the return values from the <tt class="function">ParserCreate()</tt> | |
103 | function. | |
104 | </dd></dl> | |
105 | ||
106 | <P> | |
107 | The <tt class="module">xml.parsers.expat</tt> module contains two functions: | |
108 | ||
109 | <P> | |
110 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
111 | <td><nobr><b><tt id='l2h-4304' xml:id='l2h-4304' class="function">ErrorString</tt></b>(</nobr></td> | |
112 | <td><var>errno</var>)</td></tr></table></dt> | |
113 | <dd> | |
114 | Returns an explanatory string for a given error number <var>errno</var>. | |
115 | </dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
119 | <td><nobr><b><tt id='l2h-4305' xml:id='l2h-4305' class="function">ParserCreate</tt></b>(</nobr></td> | |
120 | <td><var></var><big>[</big><var>encoding</var><big>[</big><var>, | |
121 | namespace_separator</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
122 | <dd> | |
123 | Creates and returns a new <tt class="class">xmlparser</tt> object. | |
124 | <var>encoding</var>, if specified, must be a string naming the encoding | |
125 | used by the XML data. Expat doesn't support as many encodings as | |
126 | Python does, and its repertoire of encodings can't be extended; it | |
127 | supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII. If | |
128 | <var>encoding</var> is given it will override the implicit or explicit | |
129 | encoding of the document. | |
130 | ||
131 | <P> | |
132 | Expat can optionally do XML namespace processing for you, enabled by | |
133 | providing a value for <var>namespace_separator</var>. The value must be a | |
134 | one-character string; a <tt class="exception">ValueError</tt> will be raised if the | |
135 | string has an illegal length (<code>None</code> is considered the same as | |
136 | omission). When namespace processing is enabled, element type names | |
137 | and attribute names that belong to a namespace will be expanded. The | |
138 | element name passed to the element handlers | |
139 | <tt class="member">StartElementHandler</tt> and <tt class="member">EndElementHandler</tt> | |
140 | will be the concatenation of the namespace URI, the namespace | |
141 | separator character, and the local part of the name. If the namespace | |
142 | separator is a zero byte (<code>chr(0)</code>) then the namespace URI and | |
143 | the local part will be concatenated without any separator. | |
144 | ||
145 | <P> | |
146 | For example, if <var>namespace_separator</var> is set to a space character | |
147 | ("<tt class="character"> </tt>") and the following document is parsed: | |
148 | ||
149 | <P> | |
150 | <div class="verbatim"><pre> | |
151 | <?xml version="1.0"?> | |
152 | <root xmlns = "http://default-namespace.org/" | |
153 | xmlns:py = "http://www.python.org/ns/"> | |
154 | <py:elem1 /> | |
155 | <elem2 xmlns="" /> | |
156 | </root> | |
157 | </pre></div> | |
158 | ||
159 | <P> | |
160 | <tt class="member">StartElementHandler</tt> will receive the following strings | |
161 | for each element: | |
162 | ||
163 | <P> | |
164 | <div class="verbatim"><pre> | |
165 | http://default-namespace.org/ root | |
166 | http://www.python.org/ns/ elem1 | |
167 | elem2 | |
168 | </pre></div> | |
169 | </dl> | |
170 | ||
171 | <P> | |
172 | <div class="seealso"> | |
173 | <p class="heading">See Also:</p> | |
174 | ||
175 | <dl compact="compact" class="seetitle"> | |
176 | <dt><em class="citetitle"><a href="http://www.libexpat.org/" | |
177 | >The Expat XML Parser</a></em></dt> | |
178 | <dd>Home page of the Expat project.</dd> | |
179 | </dl> | |
180 | </div> | |
181 | ||
182 | <P> | |
183 | ||
184 | <p><br /></p><hr class='online-navigation' /> | |
185 | <div class='online-navigation'> | |
186 | <!--Table of Child-Links--> | |
187 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
188 | ||
189 | <UL CLASS="ChildLinks"> | |
190 | <LI><A href="xmlparser-objects.html">13.5.1 XMLParser Objects</a> | |
191 | <LI><A href="expaterror-objects.html">13.5.2 ExpatError Exceptions</a> | |
192 | <LI><A href="expat-example.html">13.5.3 Example</a> | |
193 | <LI><A href="expat-content-models.html">13.5.4 Content Model Descriptions</a> | |
194 | <LI><A href="expat-errors.html">13.5.5 Expat error constants</a> | |
195 | </ul> | |
196 | <!--End of Table of Child-Links--> | |
197 | </div> | |
198 | ||
199 | <DIV CLASS="navigation"> | |
200 | <div class='online-navigation'> | |
201 | <p></p><hr /> | |
202 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
203 | <tr> | |
204 | <td class='online-navigation'><a rel="prev" title="13.4 htmlentitydefs " | |
205 | href="module-htmlentitydefs.html"><img src='../icons/previous.png' | |
206 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
207 | <td class='online-navigation'><a rel="parent" title="13. Structured Markup Processing" | |
208 | href="markup.html"><img src='../icons/up.png' | |
209 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
210 | <td class='online-navigation'><a rel="next" title="13.5.1 XMLParser Objects" | |
211 | href="xmlparser-objects.html"><img src='../icons/next.png' | |
212 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
213 | <td align="center" width="100%">Python Library Reference</td> | |
214 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
215 | href="contents.html"><img src='../icons/contents.png' | |
216 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
217 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
218 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
219 | <td class='online-navigation'><a rel="index" title="Index" | |
220 | href="genindex.html"><img src='../icons/index.png' | |
221 | border='0' height='32' alt='Index' width='32' /></A></td> | |
222 | </tr></table> | |
223 | <div class='online-navigation'> | |
224 | <b class="navlabel">Previous:</b> | |
225 | <a class="sectref" rel="prev" href="module-htmlentitydefs.html">13.4 htmlentitydefs </A> | |
226 | <b class="navlabel">Up:</b> | |
227 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
228 | <b class="navlabel">Next:</b> | |
229 | <a class="sectref" rel="next" href="xmlparser-objects.html">13.5.1 XMLParser Objects</A> | |
230 | </div> | |
231 | </div> | |
232 | <hr /> | |
233 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
234 | </DIV> | |
235 | <!--End of Navigation Panel--> | |
236 | <ADDRESS> | |
237 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
238 | </ADDRESS> | |
239 | </BODY> | |
240 | </HTML> |