how do I use empty namespaces in an lxml xpath query? how do I use empty namespaces in an lxml xpath query? xml xml

how do I use empty namespaces in an lxml xpath query?


Something like this should work:

import lxml.etree as etns = {"atom": "http://www.w3.org/2005/Atom"}tree = et.fromstring(xml)for node in tree.xpath('//atom:entry', namespaces=ns):    print node

See also http://lxml.de/xpathxslt.html#namespaces-and-prefixes.

Alternative:

for node in tree.xpath("//*[local-name() = 'entry']"):    print node


Use findall method.

for item in tree.findall('{http://www.w3.org/2005/Atom}entry'):     print item