XML technologies / XML / Python & XML / Getting started with Python and XML

(Excerpt from “Python & XML” by Christopher A. Jones & Fred L. Drake, Jr.)

Python and XML are very different, each with a rich history. Python is a general-purpose programming language that grew organically from scripting roots under the vision and guidance of its creator, Guido van Rossum. Guido continues to consider Python developers’ needs as the language evolves. XML, though strongly influenced by a small group of visionaries, grew up within standards committees. It has experienced quiet periods of adoption and bitter battles over its future. Why, then, bring the two technologies together?

Before combining Python and XML, there seemed to be no simple, effective way to work with XML in a distributed environment. Developers had to rely on numerous tools usable together only in cumbersome combinations. We used shell scripts and Perl for text processing and operating-system interaction, then used Java XML APIs to process XML and program networks. The shell excelled at file processing and Unix interaction, while Perl offered simple text processing and access to Unix APIs. Unfortunately, neither had an advanced object model. Java, by contrast, offered an object-oriented environment, a robust networking API, threads and GUI development. However, we immediately found its text processing lacking; scripting languages usually offered powerful text facilities. Python provided a perfect solution, combining the strengths of all these approaches.

Like most scripting languages, Python provides excellent text and file processing. Unlike most, it also offers a powerful object-oriented environment with a robust platform API for networking, threads and GUI development. Components written in C or C++ can extend it easily, connecting it to most existing libraries. Moreover, Python has proved more portable than other popular interpreted languages, running readily on platforms as different as massively parallel Connection Machines, PDAs (Personal Digital Assistants) and embedded systems. Consequently, Python is excellent for XML programming and distributed application development.

One could say Python brings order and robustness to scripting as Java once did to C++. There are trade-offs. Moving from C++ to Java gives you a simpler language with a stronger object-oriented foundation. Fewer low-level memory-management and hardware details provide greater robustness and better ways to find coding errors. You also gain a rich API with simple thread management, networking, and support for Internet technologies and interfaces. As expected, this flexibility costs some performance compared with C and C++.

Similarly, choosing Python rather than C, C++ or even Java means accepting trade-offs: some performance is exchanged for robustness and faster development. In enterprise and Internet systems, reliable software, flexible design, and rapid growth and delivery offset possible performance gains from languages such as C++. You can regain some performance by implementing critical components in C or C++, but defer that until measurements identify real problems rather than merely possible ones. Analyzing performance and writing C/C++ extensions are topics for other books.

Whatever your views on scripting languages, Java or C++, this book focuses on XML and Python. For readers with little XML experience, we begin by explaining why it matters. Then we use XML from Python and explore how it simplifies building XML applications.

   

  

 

 

 

back to top