web-servicesandroid-studioxml-parsingksoap

how can i show just a value from a web service xml


i have the following code and it gets me a string from result but i tried to find a way that show me only a value from the string of xml service but i cant, how to only show that value?, in te code you can see only the conexion to the web service, should i need to parse the xml string?

--XML

<string xmlns="http://www.webserviceX.NET">
<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather> 
<Location>Mexico City / Licenci, Mexico (MMMX) 19-26N 099-06W</Location>
<Time>Feb 09, 2016 - 11:44 AM EST / 2016.02.09 1644 UTC</Time>
<Wind> Calm:0</Wind> 
<Visibility> 7 mile(s):0</Visibility>
<SkyConditions> mostly cloudy</SkyConditions> 
<Temperature> 51 F (11 C)</Temperature> 
<DewPoint> 30 F (-1 C)</DewPoint> 
<RelativeHumidity> 43%</RelativeHumidity> 
<Pressure> 30.47 in. Hg (1031 hPa)</Pressure> 
<Status>Success</Status> 
</CurrentWeather>
</string>

--

public class UploadData {
public String getWeather(String city,String country){
    String resultado = null;
    SoapObject callWS;
    callWS = new SoapObject("http://www.webserviceX.NET","GetWeather");
    callWS.addProperty("CityName", city);
    callWS.addProperty("CountryName",country);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.bodyOut = callWS;
    envelope.dotNet  = true;
    envelope.encodingStyle = SoapSerializationEnvelope.XSD;
    HttpTransportSE androidHttpTranport = null;
    try {
        String conexion = "http://www.webservicex.com/globalweather.asmx?WSDL";
        androidHttpTranport = new HttpTransportSE(conexion);
        androidHttpTranport.call("http://www.webserviceX.NET/GetWeather",envelope);
        result = envelope.getResponse().toString();



    }catch (Exception e){
        System.out.println(e.getMessage());
        result=e.getMessage();
    }
    return result;
}}

Solution

  • Use this line

    result = (SoapObject) envelope.getResponse();
    

    instead of

    result = envelope.getResponse().toString();
    

    Now if you want to access some value on XML tag, you should use getProperty() method. See documentation here.

    For instance, you can try this:

    result.getProperty(1).toString();