title: parsing XML file in python with cElementTree: dealing with errors and line number in the file
body: <p>I am using the <code>cElementTree</code> library to parse XML files in Python.
  Everything is working fine</p>
  
  <p>But I would like to provide full error messages for the user when a value in the XML is not correct.</p>
  
  <p>For example, let's suppose I have the following XML:</p>
  
  <pre><code>&lt;A name="xxxx" href="yyyy"/&gt;
  </code></pre>
  
  <p>and want to tell the user if the <code>href</code> attribute doesn't exist or have a value that is not in  a given list.</p>
  
  <p>For the moment, I have something like</p>
  
  <pre><code>if elem.get("ref") not in myList:
      raise XMLException( elem, "the 'href' attribute is not valid or does not exist")
  </code></pre>
  
  <p>where my exception is caught somewhere.</p>
  
  <p>But, in addition, I would like to display the line number of the XML element in the file. It seems that the <code>cElementTree</code> doesn't store any information about the line numbers of the XML elements of the tree... :-(</p>
  
  <p><strong>Question:</strong> Is there an equivalent XML library that is able to do that?
  Or a way to have access to the position of an XML element in the XML file ?</p>
  
  <p>Thanks</p>