如何在Android中解析Web服务的XML响应

时间:2014-09-20 14:07:34

标签: android xml eclipse web-services ksoap2

嗨,大家好,我是Ksoap的新手。我设法在android上的Web服务上做了一些工作但现在我无法找到如何解析Web服务的XML响应请帮帮我。

响应中的XML

anyType
{
schema=anyType
{
element=anyType
{
complexType=anyType
{
choice=anyType
{
element=anyType
{
complexType=anyType
{
sequence=anyType
{
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
element=anyType{};
element=anyType{}; 
}; }; }; };  };  }; }; 

diffgram=anyType
{
MobileApp=anyType
{
tbl_Vehicles=anyType
{
 ID=1; 
 PlateNumber=95459;
 Latitude=25.167330;
 Longitude=55.237670;
 Status=Driving;
 Location=Sheikh Zayed Rd. Dubai; 
}; 

tbl_Vehicles=anyType
{
ID=2; 
PlateNumber=45926;
Latitude=25.127791; 
Longitude=55.114626;
Status=Parked;
Location=Alpha Tours, Palm Jumeirah, Dubai; 
}; 
}; 
}; 
}

我的代码如下

public void getVehicleList()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

request.addProperty("UserID", id );

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);
envelope.dotNet = true;

try 
{
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION_LOGIN, envelope);


    if (envelope.bodyIn instanceof SoapFault) 
    {
        String str = ((SoapFault) envelope.bodyIn).faultstring;
        Log.i("SoapFault", str);
        showDialog("Error", "Their Is Some Problem In Server Response");
    } 
    else 
    {
        SoapObject response = (SoapObject)envelope.bodyIn;

        Log.d("Veh ID 8", "Result = " + response.toString() );
   }
} 
catch (Exception e) 
{
      e.printStackTrace();
}

}

1 个答案:

答案 0 :(得分:0)

也许你很难过,因为响应不是XML?