title: Android XmlPullParser: read namespaces in RSS Feed
body: <p>I'm parsing an XML feed that looks something like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
      &lt;channel&gt;
      ...
      &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>One thing I wanted to do was get all the namespaces by URL and get the associated prefix for later parsing. For example, if I know the itunes DTD is located at: <a href="http://www.itunes.com/dtds/podcast-1.0.dtd" rel="nofollow noreferrer">http://www.itunes.com/dtds/podcast-1.0.dtd</a> I want to get the associated prefix. Here is some code I want to use to do that:</p>
  
  <pre><code>if(parser.getEventType() != START_TAG &amp;&amp; !"rss".equalsIgnoreCase(parser.getName())) {
      throw new IllegalStateException();
  }
  
  for(int i=0; i&lt;parser.getAttributeCount(); i++) {
      if(!"xmlns".equalsIgnoreCase(parser.getAttributePrefix(i))) {
          continue;
      }
      String namespace = parser.getAttributeName(i);
      String namespaceUrl = parser.getAttributeValue(i);
      if(namespaceUrl.contains("www.itunes.com")) {
          ITUNES_NAMESPACE = namespace;
      } else if(namespaceUrl.contains("www.w3.org/2005/Atom")) {
          ATOM_NAMESPACE = namespace;
      }
   }
  </code></pre>
  
  <p>However, the only attribute that shows up here is the rss "version" attribute (getAttributeCount returns 1 and the name and values for "version" and "2.0"). Is there some way to get the namespaces?</p>