title: how to parse XML response using retrofit 2.0?
body: <p>Hi am new to android programming i have gone through some links for how to parse the XML response using retrofit and i tried for below XML as shown.</p>
  
  <p>Is there any necessary changes i have to do in POJO class. but am getting NullPointer Exception in Logcat. when am trying to read the response.</p>
  
  <p>Can any one please look into it and help me out.</p>
  
  <p>this is my XML response for Login API.</p>
  
  <p>[<img src="https://i.stack.imgur.com/1aZq5.png" alt="xml_response[1]"></p>
  
  <p>Here is my MainActivity code. can any one suggest where am getting wrong.</p>
  
  <pre><code>RequestBody requestBody = RequestBody.create(MediaType.parse("text/xml"), strRequestBody);
  
      Call&lt;LoginResponseEnvelope&gt; call = RetrofitGenerator.getProductInterfaceApi().Login(requestBody);
      call.enqueue(new Callback&lt;LoginResponseEnvelope&gt;() {
          @Override
          public void onResponse(Call&lt;LoginResponseEnvelope&gt; call, Response&lt;LoginResponseEnvelope&gt; response) {
              progressbar.setVisibility(View.GONE);
  
              if (response != null) {
                  try {
                      Log.d("LoginResponse", "success response :" + response.body());
                      LoginResponseEnvelope loginResponseEnvelope = response.body();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
  
                 /* if (loginResponseEnvelope != null) {
                      Log.d("LoginResponse", "success loginResponseEnvelope :" + loginResponseEnvelope.toString());
  
                      String status = loginResponseEnvelope.getBody().getLoginResponseData().getLoginResult().getLoginInfo().toString();
  
                      Intent intent = new Intent(MainActivity.this, SuccessActivity.class);
                      startActivity(intent);
                  }*/
              }
  
              /*if (loginResponseEnvelope!=null){
  
              }*/
          }
  
          @Override
          public void onFailure(Call&lt;LoginResponseEnvelope&gt; call, Throwable t) {
              progressbar.setVisibility(View.GONE);
              Log.d("LoginResponse", "failure response :" + t.getMessage());
          }
      });
  </code></pre>
  
  <p>this is my retrofit POJO class for XML response.</p>
  
  <pre><code>public class LoginResponseEnvelope {
  
  @Element(name = "Body", required = false)
  private LoginResponseBody body;
  
  public LoginResponseBody getBody() {
      return body;
  }
  
  public void setBody(LoginResponseBody body) {
      this.body = body;
  }
  
  @Override
  public String toString() {
      return "LoginResponseEnvelope{" +
              "body=" + body +
              '}';
  }
  
  @Root(name = "Body", strict = false)
  public class LoginResponseBody {
  
      @Element(name = "LoginResponse", required = false)
      private LoginResponseData loginResponseData;
  
      public LoginResponseData getLoginResponseData() {
          return loginResponseData;
      }
  
      public void setLoginResponseData(LoginResponseData loginResponseData) {
          this.loginResponseData = loginResponseData;
      }
  
      @Root(name = "LoginResponse", strict = false)
      @Namespace(reference = "http://tempuri.org/")
      public class LoginResponseData {
  
          @Element(name = "LoginResult", required = false)
          private LoginResult loginResult;
  
          public LoginResult getLoginResult() {
              return loginResult;
          }
  
          public void setLoginResult(LoginResult loginResult) {
              this.loginResult = loginResult;
          }
  
          @Root(name = "LoginResult", strict = false)
          public class LoginResult {
  
              @Element(name = "Result", required = false)
              private LoginInfo loginInfo;
  
              public LoginInfo getLoginInfo() {
                  return loginInfo;
              }
  
              public void setLoginInfo(LoginInfo loginInfo) {
                  this.loginInfo = loginInfo;
              }
  
              @Root(name = "Result", strict = false)
              @Namespace(reference = "")
              public class LoginInfo {
  
                  @Element(name = "Success", required = false)
                  private Success success;
  
                  public Success getSuccess() {
                      return success;
                  }
  
                  public void setSuccess(Success success) {
                      this.success = success;
                  }
  
                  @Root(name = "Success", strict = false)
                  public class Success {
  
                      @ElementList(name = "CompanyDetails", inline = true)
                      private List&lt;Company&gt; companyDetails;
  
                      public List&lt;Company&gt; getCompanyDetails() {
                          return companyDetails;
                      }
  
                      public void setCompanyDetails(List&lt;Company&gt; companyDetails) {
                          this.companyDetails = companyDetails;
                      }
  
                      @Root(name = "CompanyDetails", strict = false)
                      public class Company {
  
                          @Element(name = "Id", required = false)
                          private String id;
  
                          @Element(name = "Name", required = false)
                          private String Name;
  
                          public String getId() {
                              return id;
                          }
  
                          public void setId(String id) {
                              this.id = id;
                          }
  
                          public String getName() {
                              return Name;
                          }
  
                          public void setName(String name) {
                              Name = name;
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>