Hi,
please reply also to the list.
Kenneth Miller wrote:
> On Jan 4, 2008, at 3:45 PM, Stefan Behnel wrote:
>> Kenneth Miller wrote:
>>> Is there any way to use an XSD file to generate an object in
>>> python using Objectify?
>>
>> Hmm, lxml.objectify actually works "as is", based on the XML document
>> itself
>> (i.e. an 'instance' of the schema), but without any schema
>> interaction. What
>> are you trying to achieve? Type enforcement based on schema types?
>>
>> Or do you mean 'generate an object' in the sense that you want to map an
>> objectify object to a plain Python object?
>>
> I'd like to be able to simply create the objects defined by the schema
> as python objects.
:) repeating an answer doesn't always help in understanding it.
But I think what you mean is: you have a schema and you want to generate
source code for Python objects *in advance* to represent its document
instances. That's not how lxml.objectify works.
What lxml.objectify does, is: you give it a document instance (no schema
involved) and it will create Python objects for you *at runtime* to represent
the document. That's a slight difference, and it's the reason why I asked
back. It might or might not fit what you want to achieve with these objects.
My bet is, if you validate your instance against the schema before you access
the document tree, there shouldn't be a difference in behaviour. Also, if you
want to tie specific objects to certain parts of the document, lxml will allow
you to do that - just not with an /arbitrary/ Python object, as it requires
inheritance of lxml's base objects.
Have you looked at the examples on our web page?
http://codespeak.net/lxml/dev/objectify.html#the-lxml-objectify-apihttp://codespeak.net/lxml/dev/objectify.html#python-data-typeshttp://codespeak.net/lxml/dev/element_classes.html
Stefan