How do I escape the forward slash character in an xpath query? My tags contain a url, so I need to be able to do this. I am using lxml in python.
Alternatively, is it possible for xpath to query a substring of the path? Examples are below:
xml="""
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsa="http://schemas.google.com/gsa/2007">
<gsa:content name="reportName">bbb</gsa:content>
<gsa:content name="collectionName">default_collection</gsa:content>
<gsa:content name="reportDate">date_3_25_2009</gsa:content>
</entry>
"""
When I run the following:
tree=fromstring(xml)
for elt in tree.xpath('//*'):
elt.tag
It returns:
'{http://www.w3.org/2005/Atom}entry'
'{http://schemas.google.com/gsa/2007}content'
'{http://schemas.google.com/gsa/2007}content'
'{http://schemas.google.com/gsa/2007}content'
Running tree.xpath('/entry') returns an empty list.
I need to be able to either query for ‘{http://www.w3.org/2005/Atom}entry’ as the tag, or query for ‘entry’ anywhere in the tag.
Look into
namespace prefixes[docs].If you want an element that’s in the
http://schemas.google.com/gsa/2007namespace you need to search for it like so: