Users are inputting quite complex XPaths to query the database.
They will only use one fixed namespace for the queries. Currently users have to enter expressions like:
//ns:tag1/ns:tag2 | //ns:tag3/ns:*[not(ns:tag2)]
But this syntax gets overly complicated very quickly, and takes longer to enter. Also it is quite error prone, for users who aren't overly familiar with xpath. Users would ideally input the XPath without namespaces --
//tag1/tag2 | //tag3/*[not(tag2)]
So much easier for them! But not for me. How can I deal with this kind of expression? I do know the namespace that needs to be inserted. Is there any way to automatically insert the ns in the appropriate places in the Xpath expression? I am using Python lxml. Or can I set a default namespace?
Note that *[local-name() = 'entry'] is not possible here!
edit
In python I am calling
currentNode.xpath(query, {'ns':'http://myaddress.com/userns'})
where currentNode is an etree.Element.
lxmlare you passing the users' queries?currentNode.xpath(query, {'ns':'http://myaddress.com/userns'})