Hi Andreas, Andreas Pakulat wrote:
before trying to code it I'd like to get opinions about the following.
I'd like to add a global xpath function to lxml, that takes an element (the context) and an xpath expression (as string) and returns a list of tuples. Where each tuple has
a) 3 parts, the attribute name, value and containing element b) 2 parts, the text and the element that has the text as text or tail c) 1 part, the element itself.
I'm not very comfortable with the idea of inferring the semantics of a tuple result from the number of its entries.
I'd like to have this for XPathEvaluator (so I can highlight attribute and text nodes in the tree) and I'm willing to try and implement it in lxml.
Hmmm, it feels like a rather specific requirement. What you really want is to always receive a reference to the libxml2 node that carries the result of an XPath expression. The problem is that this does not match very well with the rest of the API, where attributes 'do not exist', for example. I mean, your real problem is that you must evaluate arbitrary (opaque) XPath expressions and do not know what the non-element result of them means: Did a string come from an attribute or from element text? Which element did it come from? So you are interested in meta-data about the XPath result, not the result itself. I do not think many applications have this requirement. Stefan