我用Java创建了一个Web服务,并以xml格式返回了“类别”列表。我能够检索到此信息,并且它以这种格式返回了一个字符串
<categories>
<category>
<id> 1 </id>
<description> Description 1</description>
</category>
<category>
<id> 2 </id>
<description> Description 2</description>
</category>
</categories>
我有一个对象,该对象指的是Category,如何将该字符串转换为xml文件或某种流派,以便能够加载类别列表?
public class category{
private int id;
private String description;
public Categoria(int id, String description) {
this.id= id;
this.description= description;
}
// gets sets
}
private void RetrieveCategories(){
AcessaWsTask task = new AcessaWsTask();
String resultado = "";
try {
resultado = task.execute("http://192.168.10.104:8080/WebWs/getCategories").get();
}
catch(Exception e)
{
resultado=e.getMessage();
}
txtTitulo.setText(resultado);
}