我是Retrofit 2.1的新手,并尝试解析下面给出的XML数据。 本教程对我有帮助,但无法自行解决数据 How to Integrate XML Converter Tutorial
XML DATA
<?xml version="1.0" ?>
<!DOCTYPE TSeqSet PUBLIC "-/.......">
<TSeqSet>
<TSeq>
<TSeq_length>377</TSeq_length>
</TSeqSet>
POJO班
@Root(name = "TSeq")
public class TSeq {
@Element(name = "TSeq_length")
private long TSeq_length;
@Attribute(required = false)
private String link;
public TSeq() {}
}
JAVA CLASS实施细节
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Retrofit builder;
interface GitHubClient {
@Headers({
"Content-Type: application/xml"
})
@GET("efetch.fcgi")
Call<TSeq> getNews(@QueryMap Map<String, String> options );
}
// making retrofit for xml data handle
builder = new Retrofit.Builder()
.baseUrl(All_Constants.CommonUrl)
.client(new OkHttpClient())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
// prepare dynamic part or URI
Map<String, String> data = new HashMap<>();
data.put("id","749778981");
GitHubClient service = builder.create(GitHubClient.class);
TSeq user1 = null;
try {
user1 = service.getNews(data).execute().body();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("* * * User 1: ",user1.toString());
请帮我通过Retrofit2.1 Lib获取XML数据。
谢谢大家