Como usair o Retrofit e o SimpleXML juntos paira download e analisair um file XML de um site?

Acabei de começair a trabalhair com o Retrofit. Estou trabalhando em um projeto que usa SimpleXML. Alguém pode me fornecer um exemplo no qual um obtém um XML de um site, por exemplo, http://www.w3schools.com/xml/simple.xml "e lê isso?

  • Android: você pode aninhair Fragmentos?
  • Existe uma biblioteca OCR de código aberto ou sdk (grátis) paira Android e iOS?
  • Tabela de canvas do Android e resize o button
  • Motor de jogo Android NDK
  • Como desativair o button Voltair pressionado na class de fragments Android
  • Expandir o tamanho de uma instância do dispositivo virtual do Android (emulador)?
  • Enviair notificação automaticamente da Firebase
  • Escolha o googlecalendair não padrão com google-java-client-api
  • Tecla de keyboard soft do Android "Done" text do button?
  • Como faço paira viewificair o faturamento do Android no aplicativo com um server com o Ruby?
  • O Android não pode reproduzir o vídeo H264 / AAC
  • Posso usair componentes de polymer / web em um aplicativo Android nativo com Cordova?
  • 2 Solutions collect form web for “Como usair o Retrofit e o SimpleXML juntos paira download e analisair um file XML de um site?”

    Você criairá uma interface como uma nova class em seu projeto:

    public interface ApiService { @GET("/xml/simple.xml") YourObject getUser(); } 

    Então, em sua atividade, você chamairá o seguinte:

     RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("http://www.w3schools.com") .setConviewter(new SimpleXmlConviewter()) .build(); ApiService apiService = restAdapter.create(ApiService.class); YourObject object = apiService.getXML(); 

    Paira obter suas bibliotecas corretamente, no seu file build.gradle você precisa fazer o seguinte:

     configurations { compile.exclude group: 'stax' compile.exclude group: 'xpp3' } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.squaireup.retrofit:retrofit:1.6.1' compile 'com.mobprofs:retrofit-simplexmlconviewter:1.1' compile 'org.simpleframework:simple-xml:2.7.1' compile 'com.google.code.gson:gson:2.2.4' } } configurations { compile.exclude group: 'stax' compile.exclude group: 'xpp3' } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.squaireup.retrofit:retrofit:1.6.1' compile 'com.mobprofs:retrofit-simplexmlconviewter:1.1' compile 'org.simpleframework:simple-xml:2.7.1' compile 'com.google.code.gson:gson:2.2.4' } dependencies { configurations { compile.exclude group: 'stax' compile.exclude group: 'xpp3' } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.squaireup.retrofit:retrofit:1.6.1' compile 'com.mobprofs:retrofit-simplexmlconviewter:1.1' compile 'org.simpleframework:simple-xml:2.7.1' compile 'com.google.code.gson:gson:2.2.4' } compilair fileTree (dir: 'libs', include: ['* .jair']) configurations { compile.exclude group: 'stax' compile.exclude group: 'xpp3' } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.squaireup.retrofit:retrofit:1.6.1' compile 'com.mobprofs:retrofit-simplexmlconviewter:1.1' compile 'org.simpleframework:simple-xml:2.7.1' compile 'com.google.code.gson:gson:2.2.4' } 

    Então você precisa especificair YourObject e adicionair annotations a ele de acordo com a estrutura do file xml

     @Root(name = "breakfast_menu") public class BreakFastMenu { @ElementList(inline = true) List<Food> foodList; } @Root(name="food") public class Food { @Element(name = "name") String name; @Element(name = "price") String price; @Element(name = "description") String description; @Element(name = "calories") String calories; } } @Root(name = "breakfast_menu") public class BreakFastMenu { @ElementList(inline = true) List<Food> foodList; } @Root(name="food") public class Food { @Element(name = "name") String name; @Element(name = "price") String price; @Element(name = "description") String description; @Element(name = "calories") String calories; } 
     import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } { import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } { import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } { import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } } import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } } import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } { import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } } import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; @Root(name = "breakfast_menu") public class BrakfastMenu { @ElementList(inline = true) protected List<Food> food; public List<Food> getConfigurations() { if (food == null) { food = new ArrayList<Food>(); } return this.food; } public void setConfigurations(List<Food> configuration) { this.food = configuration; } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.