title: Android Retrofit 2 Simple XML Converter
body: <p>I am using Retrofit <strong>2.1.0</strong> and Retrofit SimpleXML Converter <strong>2.1.0</strong>. I added simplexmlconverter to retrofit instance with addConverterFactory method.</p>
  
  <p>XML is below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" version="2.0"&gt;
     &lt;channel&gt;
        &lt;title&gt;title&lt;/title&gt;
        &lt;description&gt;&lt;/description&gt;
        &lt;language&gt;en-us&lt;/language&gt;
        &lt;item&gt;
           &lt;title&gt;text&lt;/title&gt;
           &lt;link&gt;text&lt;/link&gt;
           &lt;description&gt;text&lt;/description&gt;
           &lt;enclosure url="text" length="2043520" type="image/jpeg" /&gt;
           &lt;guid isPermaLink="false"&gt;text&lt;/guid&gt;
           &lt;pubDate&gt;Fri, 17 Jun 2016 11:43 EDT&lt;/pubDate&gt;
           &lt;source url="text"&gt;text&lt;/source&gt;
        &lt;/item&gt;
        &lt;item&gt;
           &lt;title&gt;text&lt;/title&gt;
           &lt;link&gt;text&lt;/link&gt;
           &lt;description&gt;text&lt;/description&gt;
           &lt;enclosure url="text" length="1735257" type="image/jpeg" /&gt;
           &lt;guid isPermaLink="false"&gt;text&lt;/guid&gt;
           &lt;pubDate&gt;Thu, 16 Jun 2016 10:17 EDT&lt;/pubDate&gt;
           &lt;source url="text"&gt;&lt;/source&gt;
        &lt;/item&gt;
        &lt;item&gt;
           &lt;title&gt;text&lt;/title&gt;
           &lt;link&gt;text&lt;/link&gt;
           &lt;description&gt;text&lt;/description&gt;
           &lt;enclosure url="text" length="3763157" type="image/jpeg" /&gt;
           &lt;guid isPermaLink="false"&gt;text&lt;/guid&gt;
           &lt;pubDate&gt;Wed, 15 Jun 2016 10:02 EDT&lt;/pubDate&gt;
           &lt;source url="text"&gt;text&lt;/source&gt;
        &lt;/item&gt;
     &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>My retrofit api client relevant code : <strong>RetrofitAPIClient</strong></p>
  
  <pre><code>OkHttpClient client = new OkHttpClient.Builder()
              .addInterceptor(loggingInterceptor)
              .build();
  
  Retrofit retrofit = new Retrofit.Builder()
          .baseUrl(BASE_URL)
          .client(client)
          .addConverterFactory(SimpleXmlConverterFactory.create())
          .build();
  
  apiService = retrofit.create(MyService.class);
  </code></pre>
  
  <p><strong>ArticleResponse.java</strong></p>
  
  <pre><code>import org.simpleframework.xml.Element;
  import org.simpleframework.xml.ElementList;
  import org.simpleframework.xml.Root;
  
  import java.util.List;
  
  @Root(name = "rss")
  public class ArticleResponse {
  
      @Element(name = "channel")
      public Channel channel;
  
      public class Channel {
  
          @ElementList
          public List&lt;Article&gt; articles;
      }
  }
  </code></pre>
  
  <p><strong>Article.java</strong></p>
  
  <pre><code>import org.simpleframework.xml.Attribute;
  import org.simpleframework.xml.Element;
  import org.simpleframework.xml.Text;
  
  @Element(name = "item")
  public class Article {
  
      @Element(name = "title")
      private String title;
  
      @Element(name = "link")
      private String link;
  
      @Element(name = "description")
      private String description;
  
      @Element(name = "enclosure")
      private Enclosure enclosure;
  
      @Element(name = "guid")
      private String guid;
  
      @Element(name = "pubDate")
      private String pubDate;
  
      @Element(name = "source")
      private Source source;
  
      public class Enclosure {
  
          @Attribute(name = "url")
          private String url;
  
          @Attribute(name = "length")
          private long length;
  
          @Attribute(name = "type")
          private String type;
      }
  
      public class Source {
  
          @Attribute(name = "url")
          private String url;
  
          @Text
          private String text;
      }
  }
  </code></pre>
  
  <p>Error is :</p>
  
  <pre><code>06-18 20:31:22.894 W/System.err: java.lang.RuntimeException: org.simpleframework.xml.core.AttributeException: Attribute 'version' does not have a match in class [my-package].webservice.response.ArticleResponse at line 1
  06-18 20:31:22.894 W/System.err:     at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:44)
  06-18 20:31:22.894 W/System.err:     at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:23)
  06-18 20:31:22.894 W/System.err:     at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116)
  06-18 20:31:22.894 W/System.err:     at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
  06-18 20:31:22.894 W/System.err:     at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)
  06-18 20:31:22.894 W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
  06-18 20:31:22.894 W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
  06-18 20:31:22.894 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  06-18 20:31:22.894 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  06-18 20:31:22.894 W/System.err:     at java.lang.Thread.run(Thread.java:818)
  06-18 20:31:22.894 W/System.err: Caused by: org.simpleframework.xml.core.AttributeException: Attribute 'version' does not have a match in class [my-package].webservice.response.ArticleResponse at line 1
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite.readAttribute(Composite.java:494)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite.readAttributes(Composite.java:413)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite.access$300(Composite.java:59)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1382)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite.read(Composite.java:201)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Composite.read(Composite.java:148)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Persister.read(Persister.java:625)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Persister.read(Persister.java:606)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Persister.read(Persister.java:584)
  06-18 20:31:22.895 W/System.err:     at org.simpleframework.xml.core.Persister.read(Persister.java:543)
  06-18 20:31:22.895 W/System.err:     at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:36)
  06-18 20:31:22.895 W/System.err:    ... 9 more
  </code></pre>