XML scanning for value



I have an XML with the following structure that I'm getting from an API -



<entry>
<id>2397</id>
<title>action_alert</title>
<tes:actions>
<tes:name>action_alert</tes:name>
<tes:type>2</tes:type>
</tes:actions>
</entry>


I am scanning for the ID by doing the following -



sourceobject = etree.parse(urllib2.urlopen(fullsourceurl))
source_id = sourceobject.xpath('//id/text()')[0]


I also want to get the tes:type



source_type = sourceobject.xpath('//tes:actions/tes:type/text()')[0]


Doesn't work. It gives the following error -


lxml.etree.XPathEvalError: Undefined namespace prefix


How do I get it to ignore the namespace?


Alternatively, I know the namespace which is this -



<tes:action xmlns:tes="http://ift.tt/1CdnEMZ">

No comments:

Post a Comment