I have a set of XPATHS
for this XML format. The problem is that sometimes, it has specified namespace.
<?xml version="1.0" encoding="UTF-8"?>
<SHOP xmlns="http://www.zbozi.cz/ns/offer/1.0">
<SHOPITEM>
<PRODUCTNAME>Crysta váza 4 CM</PRODUCTNAME>
<DESCRIPTION><![CDATA[Český producent je vážený po celém světě
I can't just do this in this case to get all SHOPITEM items:
root.xpath('//SHOPITEM')
I need to specify namespace and then prefix every TAG.
root.xpath('//g:SHOPITEM',namespaces={'g':'http://www.zbozi.cz/ns/offer/1.0'})
Becasue when I do this:
root.xpath('//SHOPITEM',namespaces={'':'http://www.zbozi.cz/ns/offer/1.0'})
It says:
empty namespace prefix is not supported in xpath
But I can't just prefix all TAGS with 'g'. Is there a better way to do that? Make lxml
tree to act like there was no namespace
or just automatically parse it?