DTD Parsing

Stefan Behnel stefan_ml at behnel.de
Wed Nov 10 01:00:54 EST 2010


Asun Friere, 10.11.2010 06:41:
> On Nov 10, 4:11 pm, Stefan Behnel wrote:
>
>> What's your interest in parsing a DTD if you're not up to validating XML?
>
> Spitting out boilerplate code.
>[...]
> A few years back I used a similar technique to write some boiler plate
> python code where xml was isomorphically represented on a class per
> element basis (which will no doubt offend some people's sense of
> generalisation, but is none the less an interesting way to work with
> XML).

Give lxml.objectify a try. It doesn't use DTDs, but does what you want.

There are also some other similar tools like gnosis.objectify or Amara. I 
never benchmarked them in comparison, but I'd be surprised if 
lxml.objectify wasn't the fastest. I'd be interested in seeing the margin, 
though, in case anyone wants to give it a try.

It's generally a good idea to state what you want to achieve, rather than 
just describing the failure of an intermediate step of one possible path 
towards your hidden goal. This list has a huge history of finding shortcuts 
that the OPs didn't think of.

Stefan




More information about the Python-list mailing list