[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

Beyond these parsing tools, Python also ships with an xmlrpc package to support the
client and server sides of the XML-RPC protocol (remote procedure calls that transmit
objects encoded as XML over HTTP), as well as a standard HTML parser, html.parser,
that works on similar principles and is presented later in this chapter. The third-party
domain has even more XML-related tools; most of these are maintained separately from
Python to allow for more flexible release schedules. Beginning with Python 2.3, the
Expat parser is also included as the underlying engine that drives the parsing process.


XML Parsing in Action


XML processing is a large, evolving topic, and it is mostly beyond the scope of this
book. For an example of a simple XML parsing task, though, consider the XML file in
Example 19-8. This file defines a handful of O’Reilly Python books—ISBN numbers
as attributes, and titles, publication dates, and authors as nested tags (with apologies
to Python books not listed in this completely random sample—there are many!).


Example 19-8. PP4E\Lang\Xml\books.xml




Python & XML
December 2001
Jones, Drake


Programming Python, 4th Edition
October 2010
Lutz


Learning Python, 4th Edition
September 2009
Lutz


Python Pocket Reference, 4th Edition
October 2009
Lutz


Python Cookbook, 2nd Edition
March 2005
Martelli, Ravenscroft, Ascher


Python in a Nutshell, 2nd Edition
July 2006
Martelli



1430 | Chapter 19: Text and Language

Free download pdf