Chapter 5. First-class functions in action with XML

 

This chapter covers

  • First-class and higher order functions
  • Python decorators
  • Reading and writing XML
  • An XML file format for MultiDoc

In the previous chapter, we started creating a multipage document editor called MultiDoc. The aim is to create a desktop application that can load and save multipage documents stored in a single file. In this chapter, we show the implementation of a core part of this specification: the ability to save and load multipage documents stored as XML. You’ll add new load and save commands to MultiDoc, using classes in the System.Xml assembly. In the process, we’ll explore an extensible approach to reading XML with IronPython.

One of the big differences between Python and traditional .NET languages is its support for first-class functions. We start this chapter by looking at what first-class functions are and how they can help you write shorter and more beautiful code. Next, we turn our attention to working with the .NET XML classes and putting what you’ve learned about functions to work.

First, on with the first-class functions.

5.1. First-class functions

In a programming language, functions are first class if they’re just another kind of object—you can create them at runtime and pass them around your code, including using them as arguments to functions or return values from functions.

5.2. Representing documents with XML

5.3. Reading XML

5.4. Handler functions for MultiDoc XML

5.5. The Open command

5.6. Summary

sitemap