使用.NET WebService - 从Android中的asmx WebService解析数据数组

时间:2013-02-22 13:10:04

标签: android web-services xml-parsing asmx android-parser

我有一个带有asmx扩展名的.NET Web服务。 服务http://www.web.com/SampleService/SampleService.asmx有两个端点:

首先是http://www.web.com/SampleService/SampleService.asmx/GetName 它以下列格式提供客户的名称: enter image description here

类似地,第二个端点http://www.web.com/SampleService/SampleService.asmx/GetTax也返回一些XML数据。

我想从链接http://www.web.com/SampleService/SampleService.asmx

解析这两个xml数据

我已阅读this教程,其中介绍了如何使用kSOAP2 - library在Android中使用Web服务应用程序。但是在本教程中,他们解释了如何将数据传递给Web并进行一些添加操作。但我需要解析上面给出的asmx链接中的xml数据,并将结果更新为ListView。我怎样才能做到这一点?请有人帮我提供一个完整的例子吗?

1 个答案:

答案 0 :(得分:2)

private static void parseResponse(InputStream is, SoapEnvelope envelope)
          throws Throwable {
        try {
          XmlPullParser xp = new KXmlParser();
          xp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);                          

          xp.setInput(is, "UTF-8"); //UTF-8

          envelope.parse(xp);
        } catch (Throwable e) {           
            Log.e(LOG_TAG, "Error reading/parsing SOAP response", e);
            throw e;
        }
      }

...

parseResponse(is, envelope);
Object bodyIn = envelope.bodyIn;            
        if (bodyIn instanceof SoapFault) {
            throw (SoapFault) bodyIn;
        }

其中is是来自您的网络请求的输入流。如果解析没问题,bodyIn将包含SoapObject

相关问题