
On 30.05.06 22:10:06, Stefan Behnel wrote:
Andreas Pakulat wrote:
very recently I needed a program that evaluates a xpath and displays the "result" graphically in a tree of the xml file that was used. I found XPath Explorer a java application, however it does quite some more stuff than I need and there certain things that just don't work as I want.
I figured I could very easily provide something similar using lxml and PyQt4.
That sounds pretty interesting. Please post a link when you have something usable.
I will.
However if I want to highlight the tree node that the xpath matches I have a "problem" when the xpath matches attributes or text nodes. So the question is: Is there a way using lxml to find out to which element a certain non-element result of an xpath evaluation belongs?
Not straight away. Both are returned as strings, so you loose the information where it came from.
Yeah, tell me ;-)
A 'stupid idea' would be to fiddle with the XPath expression and add a function call after each traversed node that stores the element in a list. You could then trace the evaluation path.
Something like "a/b//c[true()]/d/text()" -> "a[store(.)]/b[store(.)]//c[(true()) and store(.)]/d[store(.)]/text()"
But that would require you to 'parse' the expression, I don't know if you can get that done with regexps...
uh oh. No.
I guess I'll go with PyXML and it's dom-Model then. That'll give me a proper AttrNode for the attributes.
Thanks for the clarification.
Andreas