Creating referenceable objects from XML
Alan Kennedy
alanmk at hotmail.com
Sun Dec 11 16:03:24 EST 2005
[Michael Williams]
> I need it to somehow convert my XML to intuitively referenceable
> object. Any ideas? I could even do it myself if I knew the mechanism
> by which python classes do this (create variables on the fly).
You seem to already have a fair idea what kind of model you need, and to
know that there is a simple way for you to create one. I encourage you
to progress on this path: it will increase the depth of your understanding.
One mistake I think that some people make about XML is relying on other
peoples interpretations of the subject, rather than forming their own
opinions.
The multitude of document models provided by everyone and his mother all
make assumptions about how the components of the model will be accessed,
in what order those components will be accessed, how often and when, how
memory efficient the model is, etc, etc.
To really understand the trade-offs and strengths of all the different
models, it is a good exercise to build your own object model. It's a
simple exercise, due to pythons highly dynamic nature. Understanding
your own model will help you understand what the other models do and do
not provide. You can then evaluate other off-the-shelf models for your
specific applications: I always find different XML tools suit different
situations.
See this post of mine from a couple years back about different ways of
building your own document/data models.
http://groups.google.com/group/comp.lang.python/msg/e2a4a1c35395ffec
I think the reference to the ActiveState recipe will be of particular
interest, since you could have a running example very quickly indeed.
See also my tutorial post on extracting document content from a SAX
stream. I gave the example of a simple stack-based xpath-style
expression matcher.
http://groups.google.com/group/comp.lang.python/msg/6853bddbb9326948
Also contained in that thread is an illuminating and productive
discussion between the effbot and myself about how wonderfully simple
ElementTree makes this, not to mention unbeatably efficient.
this-week-i-ave-been-mostly-using-kid-for-templating-ly'yrs,
--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
More information about the Python-list
mailing list