Python & XML - XML Processing with Python, First Edition (2002).pdf

(3583 KB) Pobierz
279710630 UNPDF
279710630.001.png
Python & XML
Christopher A. Jones
Fred L. Drake, Jr.
Publisher: O'Reilly
First Edition January 2002
ISBN: 0-596-00128-2, 384 pages
Python is an ideal language for manipulating XML, and this new volume
gives you a solid foundation for using these two languages together.
Complete with practical examples that highlight common application tasks,
the book starts with the basics then quickly progresses to complex topics
like transforming XML with XSLT and querying XML with XPath. It also
explores more advanced subjects, such as SOAP and distributed web
services.
279710630.002.png 279710630.003.png
Dedication
We would like to dedicate this book to Frank Willison, O'Reilly Editor-in-
Chief and Python Champion
——Christopher A. Jones and Fred L. Drake, Jr.
Frank will be remembered in the Python community for the several great
Python books that he made possible, memories of his participation in
many Python conferences, and his Frankly Speaking columns. The Python
world (and the world at large) won't be the same without Frank.
——Guido van Rossum, Python creator
Preface
This book comes to you as a result of the collaboration of two authors who became
interested in the topic in very different ways. Hopefully our motivations will help you
understand what we each bring to the book, and perhaps prove to be at least a little
entertaining as well.
Chris Jones started using XML several years ago, and began using Python more recently.
As a consultant for major companies in the Seattle area, he first used XML as the core
data format for web site content in a home-grown publishing system in 1997. But he
really became an XML devotee when developing an open source engine, which
eventually became the key technology for Planet 7 Technologies. As a consultant, he
continues to use XML on an almost daily basis for everything from configuration files to
document formats.
Chris began dabbling in Python because he thought it was a clean, object-oriented
alternative to Perl. A long-time Unix user (but one who frequently finds himself working
with Windows in Seattle), he has grown accustomed to scripting languages that place the
full Unix API in the hands of developers. Having used far too much Java and ASP in web
development over the years, he found Python a refreshing way to keep object-orientation
while still accessing Unix sockets and threads—all with the convenience of a scripting
language.
The combination of Python and XML brings great power to the developer. While XML is
a potent technology, it requires the programmer to use objects, interfaces, and strings.
Python does so as well, and therefore provides an excellent playpen for XML
development. The number of XML tools for Python is growing all the time, and Chris
can produce an XML solution in far less time using Python than he can with Java or C++.
Of course, the cross-platform nature of Python keeps our work consistently usable
whether we're developing on Windows, Linux, or a Unix variant—the combination of
which we both seem to find powerful.
Fred Drake came to Python and XML from a different avenue, arriving at Python before
XML. He discovered Python while in graduate school experimenting with a number of
programming languages. After recognizing Python as an excellent language for rapid
development, he convinced his advisors that he should be able to write his masters
project using Python. In the course of developing the project, he became increasingly
interested in the Python community. He then made his first contributions to the Python
standard library, and in so doing became noticed by a group of Python programmers
working on distributed systems projects at the research organization of CNRI. The group
was led by Guido van Rossum, the creator of Python. Fred joined the team and learned
more about distributed systems and gluing systems together than he ever expected
possible, and he loved it.
While still in graduate school, Fred argued that Python's documentation should be
converted to a more structured language called SGML. After a few years at CNRI, he
began to do just that, and was able to sink his teeth into the documentation more
vigorously. The SGML migration path eventually changed to an XML migration path as
XML acceptance grew. Though that goal has not yet been achieved (he is still working on
it), Fred has substantially changed the way the documentation is maintained, and it now
represents one of the most structured applications of the typesetting and document
markup system developed by Donald Knuth and Leslie Lamport.
Over time, the team from CNRI became increasingly focused on the development of
Python, and moved on to form PythonLabs. Fred remained active in XML initiatives
around Python and pushed to add XML support to the standard library. Once this was
achieved, he returned to the task of migrating the Python documentation to XML, and
hopes to complete this project soon.
Audience
This book is for anyone interested in learning about using Python to build XML
applications. The bulk of the material is suited for programmers interested in using XML
as a data interchange format or as a transformable format for web content, but the first
half of the book is also useful to those interested in building more document-oriented
applications.
We do not assume that you know anything about XML, but we do assume that you have
looked at Python enough that you are comfortable reading straightforward Python code;
however, you do not need to be a Python guru. If you do not know at least a little Python,
please consult one of the many excellent books that introduce the language, such as
Learning Python , by Mark Lutz and David Ascher and Lutz (O'Reilly, 1999). For the
sections where web applications are developed, it helps to be familiar with general
concepts related to web operations, such as HTTP and HTML forms, but sufficient
information is included to get you started with basic CGI scripting.
Organization
This book is divided into ten chapters and six appendixes, as follows:
Chapter 1
This chapter offers a broad overview of XML and why Python is particularly
well-suited to XML processing.
Chapter 2
This chapter provides a good introduction to XML for newcomers and a refresher
for programmers who have some familiarity with the standard.
Chapter 3
This chapter gives a detailed introduction to using Python with the SAX interface,
for generating parse events from an XML data stream.
Chapter 4
This chapter provides an introduction to working with DOM, which is the
dominant object-oriented, tree-based API to an XML document.
Chapter 5
This chapter discusses using a traversal language to extract portions of documents
that meet your application's requirements.
Chapter 6
Zgłoś jeśli naruszono regulamin