我如何才能仅显示来自 Web 服务的值 xml

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

我有以下代码,它从结果中获取了一个字符串,但我试图找到一种方法,只显示 xml 服务字符串中的一个值,但我不能,如何只显示那个值?,在 te 代码中,您只能看到与 Web 服务的连接,我是否需要解析 xml 字符串?

--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;
}}

使用这条线

result = (SoapObject) envelope.getResponse();

而不是

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

现在如果你想访问 XML 标签上的一些值,你应该使用 getProperty() 方法。请参阅文档 here

例如,你可以试试这个:

result.getProperty(1).toString();