[lxml-dev] Development of Extentions
Hello all, For inkscape we are looking to create a pysvg python module based on lxml; I would like very much to base the extentions on the perl based SVG::DOM2 modules which have not only XML controls but SVG methods too. I've been looking at the documentation trying to figure it all out how this can be done. So far what I think needs to happen is: we create a class that inherrits from lxml.ElementTree that will grab the right element class depending on the element name and namespace. then we make a whole bunch of classes that inherrit from the lxml.Element class which will become the controls into the lxml backend. does this ream sane? Best Regards, Martin Owens
Hi, Martin Owens wrote:
For inkscape we are looking to create a pysvg python module based on lxml; I would like very much to base the extentions on the perl based SVG::DOM2 modules which have not only XML controls but SVG methods too.
I assume what you mean here is: you want to write a Python module based on lxml and mimic the API of the existing Perl module, right?
I've been looking at the documentation trying to figure it all out how this can be done.
I assume you already read through this document: http://codespeak.net/lxml/dev/element_classes.html especially the last section on implementing namespaces: http://codespeak.net/lxml/dev/element_classes.html#id1
So far what I think needs to happen is: we create a class that inherrits from lxml.ElementTree that will grab the right element class depending on the element name and namespace.
lxml.etree does that for you, as explained in the links above.
then we make a whole bunch of classes that inherrit from the lxml.Element class which will become the controls into the lxml backend.
Actually, that would be lxml.etree.ElementBase. There are a couple of examples how this can look like. One is the upcoming Atom namespace implementation: https://svn.openplans.org/svn/TaggerStore/trunk/taggerstore/atom.py Then, there's an HTML utility implementation: http://codespeak.net/svn/lxml/branch/html/src/lxml/html/__init__.py Another is the Pyrex-implemented lxml.objectify module: http://codespeak.net/svn/lxml/trunk/src/lxml/objectify.pyx A few lines of advice: * Use a common superclass (a subclass of ElementBase) for all namespace classes. * Try to use inheritance to provide a consistent API over different Element classes. * Send a link to your code to the list as soon as you have something available, as others might be interested and might want to comment on the code. If it's any useful, I would love to integrate it into lxml. Stefan
Stefan Behnel wrote:
There are a couple of examples how this can look like.
Ah, and another one (which might actually be the most interesting to you, as it's close to what you are up to), is MathDOM, a MathML implementation: http://sourceforge.net/projects/mathdom http://mathdom.cvs.sourceforge.net/mathdom/mathml/lmathdom.py (can't check the second link at the moment, as SF's CVS seems to be a bit dead) Hope it helps, Stefan
participants (2)
-
Martin Owens -
Stefan Behnel