title: Parse an XML with multiple elements using Python with sax
body: <p>I am trying to parse an XML file with Python using SAX.</p>
  
  <p>The document has multiple elements with the same name. I want to print some of the attributes of the elements, but the program just prints the attributes of the last element encountered in the document.</p>
  
  <p>This is the code:</p>
  
  <pre><code># art.py
  import sys
  
  from xml.sax import make_parser 
  from handlers import ArticleHandler
  
  ch = ArticleHandler( ) 
  saxparser = make_parser( )
  
  saxparser.setContentHandler(ch)
  saxparser.parse(sys.stdin)
  
  print "TYPE:", ch.TYPE
  print "SUBTYPE:" , ch.SUBTYPE
  
  
  # handlers.py
  from xml.sax.handler import ContentHandler
  
  class ArticleHandler(ContentHandler):
  
   TYPE = ""
   SUBTYPE = ""
  
   def startElement(self, name, attrs):
       if name == "relation":
           self.TYPE = attrs.get("TYPE", "") 
           self.SUBTYPE = attrs.get("SUBTYPE")
  </code></pre>
  
  <p>This is the XML:</p>
  
  <pre><code>    &lt;relation ID="CNN_CF_20030303.1900.00-R3" TYPE="ORG-AFF" SUBTYPE="Employment"&gt;
      ...
      &lt;/relation&gt;
      &lt;relation ID="CNN_CF_20030303.1900.00-R4" TYPE="ORG-AFF" SUBTYPE="Membership"&gt;
      ...
      &lt;/relation&gt;
  </code></pre>
  
  <p>For this input the output is </p>
  
  <pre><code>    TYPE:ORG-AFF
      SUBTYPE:Membership
  </code></pre>
  
  <p>whereas the expected output is</p>
  
  <pre><code>    TYPE:ORG-AFF
      SUBTYPE:Employment
      TYPE:ORG-AFF
      SUBTYPE:Membership
  </code></pre>
  
  <p>How can I fix this bug?</p>