title: Using namespaces in lxml
body: <p>I am trying to do svg parsing with <code>lxml</code> and struggle with namespaces.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>How do I iterate over all <code>image</code> tags, with <code>tree.iterfind</code> and a namsepace map? <code>tree.iterfind('image', root.nsmap)</code> does not retun anything, the uglier <code>tree.iter('{http://www.w3.org/2000/svg}image')</code> works</li>
  <li>I am trying to turn <code>image</code> tags into <code>use</code> tags. While lxml gives me an attribute dictionary with <code>xlinx:href</code> it chokes on passing this to <code>makeelement</code> is there an elegant solution?</li>
  <li>Should I use <code>lxml</code> or is there something better (more straight forward)? My goal is to rewrite <code>image</code> tags to <code>use</code> tags and embed the content of the referenced svgs in symbols. (So far <code>lxml</code> and the issues I had with namespaces seem repulsive).</li>
  </ol>
  
  <p>.</p>
  
  <pre><code>from lxml import etree
  
  def inlineSvg(path):
      parser = etree.XMLParser(recover=True)
      tree = etree.parse(path, parser)
  
      root = tree.getroot()
      print(root.nsmap)
  
  
      for img in tree.iter('{http://www.w3.org/2000/svg}image'):
      #for img in tree.iterfind('image', root.nsmap): #for some reason I can't get this to work...
          print(img)
  
          #we have to translate xlink: to {http://www.w3.org/1999/xlink} for it to work, despit the lib returning xlink: ...
          settableAttributes = dict(img.items()) #img.attribute
          settableAttributes['{http://www.w3.org/1999/xlink}href'] = settableAttributes['xlink:href']
          del settableAttributes['xlink:href']
  
          print(etree.tostring(img.makeelement('use', settableAttributes)))
  </code></pre>