O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - updating our game to use DOM processing

In this example, we'll update our game to use a DOM parser as opposed to a SAX parser. You should notice how the in-memory structure is built for us and we no longer have to maintain our own object graph. We'll reuse the same XML document for this example:

  1. Copy sax_explore.py over to a new file named dom_explore.py.
  2. At the top of the file, update your import statements so they read as follows:
    import sys
    import random
    from xml.dom.minidom import parse
    
  3. Remove all code, with the following exceptions: YouDiedError, our __metaclass__ line, and the __name__ == '__main__' section.
  4. Update the Adventure class to contain the following Python code:
     import sys import random from xml.dom.minidom import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required