Python <--> XML data binding.

Paul Prescod paul at prescod.net
Wed Jun 7 03:16:54 EDT 2000


Werner Fouche wrote:
> 
> Paul,
> 
> I should have mentioned that Breeze reads the extended DTD specification
> called DT4DTDs developed by Extensibility -- their XML Authority Editor
> can convert many XML schema language dialects to DT4DTDs. DT4DTDs
> extend standard DTDs with the data types found in W3C XML Schema
> language specification.

I'm actually pretty familiar with DT4DTDs.  :)

http://www.w3.org/TR/dt4dtd

Let me just say in my defense that I didn't have that much control over
the design!!

> The biggest benefit of a tool such as what you are developing would be to
> quickly and reliable translate industry standard XML document specifications
> (say OFX 2.0) to crisp Python code! I am looking forward to the fruits of
> your current endevour.

I want you to keep looking forward to it but I also want to tell you
that I'm not particularly interested in generating Python code. In the
vast majority of cases code generators are hacks intended either to get
around a lack of dynamicity in a programming language (not a problem
with Python) or performance problems (which in Python's case, a code
generator would likely make worse, not better). 

Motto: Code generators are hacks. Sometimes necessary hacks, but hacks
nevertheless.

Let's say you take OFX 2.0 and want to map it into objects. It is
perfectly natural in the Java world to generate class definitions
because working with dynamically typed data in Java is so incredibly
painful that otherwise you would be tearing your hair -- nay -- your
skin off. But in Python, working with dynamically typed information is a
joy. So rather than generating code I'll just make the appropriate
object for you when you need it. No recompiling in advance required.

As far as keeping the "DTD and code" in sync, that can only go so far.
If you change your DTD whatever is your code depends on the DTD's
structures will break. In Java, it will break violently because of the
static type checking. My goal is to mitigate the breakage by providing a
mapping layer between the DTD and the objects so that when the DTD
changes you change the mapping, rather than the code. Something has to
break but fixing a mapping is easier than fixing code. It's like blowing
a fuse instead of burning out your computer!

Hopefully Breeze is intelligent enough to do that too, otherwise it will
be more headache than it is worth.

If the mapping process needs to be optimized for performance for some
particular application THEN it might be time to look at a code
generator. Optimization is an appropriate task for hacks.

-- 
 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
Alabama's constitution is 100 years old, 300 pages long and has more
than 600 amendments. Highlights include "Amendment 393: Amendment of
Amendment No.  351", "Validation of Laws Regulating Court Costs in
Randolph County", "Miscegenation laws", "Bingo Games in Russell County",
"Suppression of dueling".  -
http://www.legislature.state.al.us/ALISHome.html




More information about the Python-list mailing list