如何将SOAP XML输出解析为Android中的列表视图

时间:2011-12-30 13:11:47

标签: android soap xml-parsing

有谁能告诉我如何将SOAP输出解析为列表形式?这是我的代码,我想以列表形式输出。

public class WebServices extends Activity 
{


    private static final String NAMESPACE = "http://www.webserviceX.NET";
    private static final String URL = "http://www.webservicex.net/globalweather.asmx";  
    private static final String SOAP_ACTION = "http://www.webserviceX.NET/GetWeather";
    private static final String METHOD_NAME = "GetWeather";


    @Override
     public void onCreate(Bundle savedInstanceState) 
    {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
        TextView textView = new TextView(this);
        setContentView(textView);
        SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

        request.addProperty("CountryName", "India");
        request.addProperty("CityName", "Hyderabad");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = request;
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);


        HttpTransportSE httpTransport = new HttpTransportSE(URL);

        httpTransport.debug = true;

        try
        {
            httpTransport.call(SOAP_ACTION, envelope);

            Object response = envelope.getResponse();
            textView.setText(response.toString());
            String str = removeNamespace(response.toString());
            Document document = DocumentHelper.parseText(str);
            Element ele= document.getRootElement();
            List<Element> childlist = ele.elements();
            List<String> textList = new ArrayList<String>();
            for(Element child : childlist){
            textList.add(child.getTextTrim());
        }
            System.out.print(textList);
        }

            catch(Exception e)
            {
               e.printStackTrace();
            }
    }

1 个答案:

答案 0 :(得分:0)

我建议创建一个带有数据字段的自定义ListView来保存您想要的数据,我猜天气数据/位置?然后创建一个自定义适配器,将XML绑定到ListView行。