title: How to check xmlns in every element using lxml
body: <p>I am using lxml to check Product elements as they stream in a MapReduce job. I am trying to make sure that only the correct xmlns value is present in every element. For example, every Product element should have an xmlns set to "<a href="http://mynetwork.products.com/new" rel="nofollow">http://mynetwork.products.com/new</a>":</p>
  
  <p><code>&lt;Product xmlns="http://mynetwork.products.com/new"&gt;</code></p>
  
  <p>As I check each Product element (streamed one at a time), I just want to make sure that it looks like the above. I want to check for the following potential errors:</p>
  
  <ol>
  <li>Incorrect xmlns URL:</li>
  </ol>
  
  <p><code>&lt;Product xmlns="http://mynetwork.products.com/old"&gt;</code></p>
  
  <ol start="2">
  <li>Missing URL</li>
  </ol>
  
  <p><code>&lt;Product xmlns=""&gt;</code></p>
  
  <ol start="3">
  <li>Missing xmlns key/value pair</li>
  </ol>
  
  <p><code>&lt;Product&gt;</code></p>
  
  <ol start="4">
  <li>Extra attribution in the Product element</li>
  </ol>
  
  <p><code>&lt;Product xmlns="http://mynetwork.products.com/new" something="else"&gt;</code></p>
  
  <p>I tried storing the value of Product.nsmap for each element (which is a dictionary) and then reading the values of the dictionary to validate, but it doesn't help me detect any of the below cases. There must be a way.</p>