O'Reilly Open Source Convention
Books Safari Bookshelf Conferences O'Reilly Network

Arrow Home
Arrow Registration
Arrow Speakers
Arrow Keynotes
Arrow Tutorials
Arrow Sessions
Arrow At-a-Glance
Arrow Wiki
Arrow BOFs
Arrow Events
Arrow Exhibitors
Arrow Sponsors
Arrow Hotel/Travel
Arrow Venue Map
Arrow See & Do
Arrow Tips for
Arrow Press
Arrow Mail List



XML Driven Classes in Python
Eric van der Vlist, CEO, Dyomedea

Track: Python
Date: Thursday, July 29
Time: 10:45am - 11:30am
Location: Columbia


Data driven classes are a well-known subject and a unique advantage of dynamically typed programming languages as shown last year at this conference (see for instance Data-Driven Classes in Ruby). XML documents are by nature non-regular and constantly evolving data structures and a field where data driven classes greatly improve our ability to manipulate XML documents.

This talk describes a simple Python implementation of such a class that dynamically maps XML documents exposed through the DOM into a hierarchy of objects following the principles of data driven classes and late binding (the nodes are converted into objects when they are accessed for the first time). Attendees will be able to understand the internals of data-driven XML libraries and eventually to write one.

What was van der Vlist's inspiration for this session? "The starting point has been Data-Driven Classes in Ruby, a presentation given at OSCON 2003 by Michael Granger and David McCorkhill.

"I have found the concept of classes dynamically created after data stored in a database or anywhere so elegant that I have wanted to apply it to my domain of choice, XML. Without knowing it, I had already used XML data driven libraries, but to be sure I understood the concept, I have wanted to write one that would be 'more data driven' and 'more late binding' and started to do so in the plane taking me from Portland back home in Paris..."

van der Vlist describes the coolest part of his session: "When you are using statically typed languages (such as C++, Java or C#), you need some kind of schema if you want to automate the binding of XML documents to object trees. This is, for instance, the approach of Java's JAX-B that generates Java classes from W3C XML Schema schemas.

"The approach of 'data-driven classes' shows that dynamically typed languages (such as Python, Ruby, Perl...) can dynamically bind XML instance documents to object trees which classes are dynamically created at run time from what is found in the documents themselves. This provides a very lightweight and 'pythonic' method to access to the information available in XML documents without using any XML specific stuff such as SAX, DOM or schemas exactly as this information was an object tree.

"This is also bringing the principle of 'late binding' which is one of the most important benefits of XML to its extreme and the library that I have developed actually does that binding when you first attempt to use one of these objects."

O'Reilly Home | Privacy Policy

© 2004, O'Reilly Media, Inc.