[lxml-dev] Extending lxml.etree._ElementTree

Hello again, I would like to extend the _ElementTree class to include some handy methods - write_xml/write_xhtml/write_html are examples. In addition, this should enable me to return extended ElementTrees instead of ResultTrees after an XSLT transform. What would be the best way to go about this. While I can extend the base class I am struggling to understand how I can replace etree.parse() to return these objects. While I am on the subject, what is the reason for ResultTree objects as a pose to ElementTree. Why make the distinction to the user? Thanks, Noah -- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hi Noah, Noah Slater wrote:
I would like to extend the _ElementTree class to include some handy methods - write_xml/write_xhtml/write_html are examples.
What would be the best way to go about this. While I can extend the base class I am struggling to understand how I can replace etree.parse() to return these objects.
I would create either global functions or an external class (say, ElementTreeWriter) to implement this kind of functionality. There is no easy way to replace the internal _ElementTree class. Note that there is nothing you could do from a Python subclass that you couldn't do from an external function.
In addition, this should enable me to return extended ElementTrees instead of ResultTrees after an XSLT transform.
May I ask why you would want to do that?
While I am on the subject, what is the reason for ResultTree objects as a pose to ElementTree. Why make the distinction to the user?
There is a related FAQ entry, near the bottom of the file. http://codespeak.net/svn/lxml/trunk/doc/FAQ.txt Feel free to ask back if it is unclear or doesn't answer your questions. Stefan

Hi Stefan,
In addition, this should enable me to return extended ElementTrees instead of ResultTrees after an XSLT transform.
May I ask why you would want to do that?
I wanted to have the same help functions bound to both the ElementTree and ResultTree objects - but I have now opted to have helper classes instead. Thanks, Noah -- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman
participants (2)
-
Noah Slater
-
Stefan Behnel