xpath()
Test xpath extension functions.
>>> root = SAMPLE_XML
>>> e = etree.XPathEvaluator(root, None, [extension])
>>> e.evaluate("stringTest('you')")
'Hello you'
>>> e.evaluate(u"stringTest('élan')")
u'Hello \xe9lan'
>>> e.evaluate("stringTest('you','there')")
Traceback (most recent call last):
...
TypeError: stringTest() takes exactly 2 arguments (3 given)
>>> e.evaluate("floatTest(2)")
6.0
>>> e.evaluate("booleanTest(true())")
False
>>> map(tag, e.evaluate("setTest(/body/tag)"))
['tag']
>>> map(tag, e.evaluate("setTest2(/body/*)"))
['tag', 'section']
>>> e.evaluate("argsTest1('a',1.5,true(),/body/tag)")
"a, 1.5, True, ['tag', 'tag', 'tag']"
>>> map(tag, e.evaluate("argsTest2(/body/tag, /body/section)"))
['tag', 'section', 'tag', 'tag']
>>> e.evaluate("resultTypesTest()")
Traceback (most recent call last):
...
XPathResultError: This is not a node: x
>>> try:
... e.evaluate("resultTypesTest2()")
... except etree.XPathResultError:
... print "Got error"
Got error
-
|