[lxml-dev] special string subclasses for XPath string results
Stefan Behnel
stefan_ml at behnel.de
Fri Jan 25 20:51:45 CET 2008
Hi,
one more note on this.
Stefan Behnel wrote:
> Attributes and text nodes are now handled. String results (such as returned by
> the string() function) will remain plain strings - no way to recover here.
I generalised this to make all XPath string results 'smart' subclasses of
either str or unicode. For the cases where we return strings that do not have
a clear origin (e.g. assembled by the XPath string() or concat() functions),
the getparent() method will just return None, as for the root Element of a
tree. That way, you can avoid doing any hasattr() stuff and just call
getparent() directly.
Stefan
More information about the lxml-dev
mailing list