[lxml-dev] Extending //r/text()

Hi ! I am using lxml and find it really great ! Is it possible to extend like http://codespeak.net/lxml/extensions.html functions which are similar to //r/text() ? Although I have defined "testf" ns = lxml.etree.FunctionNamespace(None) ns['testf'] = testf from running: res = test_root.xpath("//r[testf()]") res = test_root.xpath("//r/text()") res = test_root.xpath("//r/testf()") I get: lxml.etree.XPathEvalError: Invalid expression when executing "//r/testf()" Thanks in advance and regards ! -- Mateusz Korniak

Mateusz Korniak, 29.01.2010 15:49:
I am using lxml and find it really great !
Happy to hear that. :)
So that's only for the last expression, right? It's different in that it doesn't have anything to match on. "text()" is a special function in XPath that matches any text node. This special property can't be replaced with an extension function. However, you didn't write anything about your use case. There may be other ways to do what you want, such as "myfunc( //r/node() )". Stefan

Mateusz Korniak, 29.01.2010 15:49:
I am using lxml and find it really great !
Happy to hear that. :)
So that's only for the last expression, right? It's different in that it doesn't have anything to match on. "text()" is a special function in XPath that matches any text node. This special property can't be replaced with an extension function. However, you didn't write anything about your use case. There may be other ways to do what you want, such as "myfunc( //r/node() )". Stefan
participants (2)
-
Mateusz Korniak
-
Stefan Behnel