-2

应该如何解析以下 ksoap Web 服务响应。(我是 android 中这部分的新手)。

这是从我的 ksop 对 Web 服务的响应中获得的响应。我在 android 4.1 设备上重新运行它。

<?xml version = "1.0" encoding = "UTF-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetNearestStationsResponse xmlns="http://tempuri.org/">
      <GetNearestStationsResult>
        <StationsCloseBy xmlns="">
          <Station Station_id="332"
                    Station_Name="דוד המלך 30"
                    Eng_Station_Name="30 David Hamellech St."
                    Description="דוד המלך 30 מול הרבנות בשדרה"
                    Eng_Address="David ha-Melekh 30 opposite the Rabbinate"
                    Latitude="32.080000"
                    Longitude="34.785400"
                    DistanceFromStationInMeters="61"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="5"
                    NumOfAvailableDocks="15"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="331"
                    Station_Name="כיכר רבין"
                    Eng_Station_Name="Rabin Square"
                    Description="כיכר רבין  מול אבן גבירול 76 -תחנה עירייה"
                    Eng_Address="Kikar Rabin, opposite Ibn Gabirol 76 - municipality station"
                    Latitude="32.081000"
                    Longitude="34.781100"
                    DistanceFromStationInMeters="360"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="12"
                    NumOfAvailableDocks="16"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="333"
                    Station_Name="ויצמן 15-איכילוב"
                    Eng_Station_Name="15 weizman st. Ichilov Hospital"
                    Description="ויצמן 15 איכילוב במדרכה מול בית החולים"
                    Eng_Address="Weizman 11 - Hospital"
                    Latitude="32.081100"
                    Longitude="34.788800"
                    DistanceFromStationInMeters="391"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="6"
                    NumOfAvailableDocks="14"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="345"
                    Station_Name="ויצמן 1 -  בית המשפט"
                    Eng_Station_Name="1 Weizman St. - Court Justice Hall"
                    Description="ויצמן 1 בית המשפט"
                    Eng_Address="Weizman 1 - Court Justice Hall"
                    Latitude="32.077200"
                    Longitude="34.788400"
                    DistanceFromStationInMeters="476"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="4"
                    NumOfAvailableDocks="24"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="342"
                    Station_Name="שאול המלך 21 קאמרי"
                    Eng_Station_Name="21 Sauol Hamelekh- Hakameri"
                    Description="שאול המלך 21 קאמרי -במדרכה מימין למדרגות כניסה מערבית"
                    Eng_Address="Shaul ha-Melekh 21 Hakameri - on the sidewalk to the right of the west entrance stairs"
                    Latitude="32.075900"
                    Longitude="34.785100"
                    DistanceFromStationInMeters="478"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="8"
                    NumOfAvailableDocks="12"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="381"
                    Station_Name="פרישמן 77"
                    Eng_Station_Name="77 Frishman St."
                    Description="פרישמן 77-שדרות חן"
                    Eng_Address="77 Frishman St."
                    Latitude="32.079500"
                    Longitude="34.779700"
                    DistanceFromStationInMeters="488"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="10"
                    NumOfAvailableDocks="10"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="323"
                    Station_Name="תשח 2"
                    Eng_Station_Name="2 Tashah St."
                    Description="תשח 2 במדרכה"
                    Eng_Address="Tashakh 2 on the sidewalk"
                    Latitude="32.084700"
                    Longitude="34.786700"
                    DistanceFromStationInMeters="530"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="6"
                    NumOfAvailableDocks="14"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="324"
                    Station_Name="אבן גבירול 106 -בית הדואר"
                    Eng_Station_Name="106 Ibn Gvirol St. - Post Office"
                    Description="אבן גבירול 106 - בית הדואר במדרכה"
                    Eng_Address="Ibn Gabirol 106 - Post Office, on the sidewalk"
                    Latitude="32.084300"
                    Longitude="34.781600"
                    DistanceFromStationInMeters="546"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="9"
                    NumOfAvailableDocks="8"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="346"
                    Station_Name="אבן גבירול 28"
                    Eng_Station_Name="28 Ibn Gabirol St."
                    Description="אבן גבירול 28 לונדון מיניסטור מאחורי ספסל ארוך דרום לכניסה"
                    Eng_Address="Ibn Gabirol 28, London Ministore behind the long bench south of the entrance"
                    Latitude="32.075000"
                    Longitude="34.781800"
                    DistanceFromStationInMeters="642"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="12"
                    NumOfAvailableDocks="8"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
          <Station Station_id="344"
                    Station_Name="נצח ישראל 4 פינת מסריק"
                    Eng_Station_Name="4 Netsakh Yisrael St./ Masaryk"
                    Description="נצח ישראל 4 פינת מסריק - תחנה בחניה בכביש "
                    Eng_Address="Netsakh Yisrael 4 corner of Masaryk - station at the roadside parking"
                    Latitude="32.077900"
                    Longitude="34.778300"
                    DistanceFromStationInMeters="665"
                    Timestamp="2013-01-30T11:05:03.320"
                    NumOfAvailableBikes="8"
                    NumOfAvailableDocks="12"
                    IsActive="1"
                    Station_picture=""
                    Station_Phone="*6070"
                    Telefax="" />
        </StationsCloseBy>
      </GetNearestStationsResult>
    </GetNearestStationsResponse>
  </soap:Body>
</soap:Envelope>      

假设:envelope.bodyIn 是 Valid Note1 -

SoapObject response = (SoapObject) envelope.bodyIn;
int propertyCount = response.getPropertyCount();
String pro = response.getPropertyAsString(0);

Running the code above gives:
propertyCount=1
pro = 
anyType{StationsCloseBy=anyType{Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; Station=anyType{}; }; }

Note2 - ksoap response was chopped (i have removed Additional Stations tags since it does not make any difference, it caontians same fields with different data)

    Any help will be appreciated!
    Thanks!
4

2 回答 2

0
String methodName = "method_name";
String newSoapAction = "initail Url" + methodName;

        SoapObject request = new SoapObject("your namespace", methodName);    

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
        androidHttpTransport
        .setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        envelope.dotNet = true;
        androidHttpTransport.debug = true;      
        androidHttpTransport.call(newSoapAction, envelope);         

        InputStream in = new ByteArrayInputStream(androidHttpTransport.responseDump.getBytes());

您将在 Inputstream 中得到响应 进一步检查检查此

于 2013-01-30T12:38:23.887 回答
0

也许我的这段代码会帮助你找出如何去做,是西班牙语,我很抱歉西班牙语。

这段代码只从 XML 中检索属性,但对于属性是完全一样的。

祝你好运!

公共静态 ListaDocumentosPentsFirmante RetrieveFromSoap(SoapObject soap){

    SoapObject root = (SoapObject) soap.getProperty("getListaPendientesFirmanteResponse");
    ListaDocumentosPentsFirmante pagina_doc =  new ListaDocumentosPentsFirmante();
    ArrayList<DocumentoBandejaFirmanteBean> lista_doc= new  ArrayList<DocumentoBandejaFirmanteBean>();
    /* Parsing every doc entry*/
    for (int i = 0; i < root.getPropertyCount(); i++){

        Object property = root.getProperty(i);
        if(property instanceof SoapObject){
            SoapObject category_list = (SoapObject) property;

            DocumentoBandejaFirmanteBean doc= new DocumentoBandejaFirmanteBean();
            //En caso de no existis?
            if (category_list.hasProperty("codigoDocumento"))
                doc.setCodigoDocumento(Long.parseLong(category_list.getProperty("codigoDocumento").toString()));
            if (category_list.hasProperty("nombreDocumento"))
                doc.setNombreDocumento(category_list.getProperty("nombreDocumento").toString());
            if (category_list.hasProperty("nombreSolicitante"))
                doc.setNombreSolicitante(category_list.getProperty("nombreSolicitante").toString());
            if (category_list.hasProperty("revisado"))
                doc.setRevisado(Boolean.valueOf(category_list.getProperty("revisado").toString()));
            if (category_list.hasProperty("clasificado"))
                doc.setClasificado(Boolean.valueOf( category_list.getProperty("clasificado").toString()));
            if (category_list.hasProperty("tieneAnexos"))
                doc.setTieneAnexos(Boolean.valueOf( category_list.getProperty("tieneAnexos").toString()));
            if (category_list.hasProperty("nombreTipoDocumento"))
                doc.setNombreTipoDocumento(category_list.getProperty("nombreTipoDocumento").toString());
            if (category_list.hasProperty("nombreUnidadAdministrativa"))
                doc.setNombreUnidadAdministrativa(category_list.getProperty("nombreUnidadAdministrativa").toString());
            if (category_list.hasProperty("prioridad"))
                doc.setPrioridad(Integer.parseInt(category_list.getProperty("prioridad").toString()));
            //Date mdFechaAlta = DateFormat.parse(category_doc.getProperty("CATEGORY").toString());
            lista_doc.add(doc);
        }               
    }
    pagina_doc.setDocumentos(lista_doc);
    pagina_doc.setPaginaActual(Integer.parseInt(root.getProperty("paginaActual").toString()));
    pagina_doc.setTotalDocumentos(Integer.parseInt(root.getProperty("totalDocumentos").toString()));
    pagina_doc.setTotalPaginas(Integer.parseInt(root.getProperty("totalPaginas").toString()));

    return pagina_doc;
}
于 2013-01-30T13:34:06.527 回答