Ajuda com xml, html?

1 resposta
Tomassoni

Galera queria pegar os dados sobre previsão de tempo de um site [url]http://www.webservicex.com/globalweather.asmx/GetWeather?CityName=Sao%20Paulo&CountryName=Brazil[/url]

O resultado no browser é o seguinte :




Sao Paulo/Congonhas Aeroporto, Brazil (SBSP) 23-37S 046-39W 802M

from the N (350 degrees) at 10 MPH (9 KT):0
greater than 7 mile(s):0
mostly cloudy
80 F (27 C)
69 F (21 C)
69%
29.91 in. Hg (1013 hPa)
Success

Eu estou obtendo ele com o seguinte código:
public static Document getDocument( DocumentBuilder db, String urlString ) {
        try {
            URL url = new URL( urlString );
            
            try {
                URLConnection URLconnection =  url.openConnection( ) ;
                HttpURLConnection httpConnection = (HttpURLConnection) URLconnection;
                
                int responseCode = httpConnection.getResponseCode( ) ;
                if ( responseCode == HttpURLConnection.HTTP_OK) {
                    InputStream in = httpConnection.getInputStream( ) ;
                    try {
                        Document doc = db.parse( in );
                        return doc;
                    } catch(org.xml.sax.SAXException e ) {
                        e.printStackTrace( ) ;
                    }
                } else {
                    System.out.println( "HTTP connection response != HTTP_OK" );
                    
                }
            } catch ( IOException e ) {
                e.printStackTrace( ) ;
            } // Catch
        } catch ( MalformedURLException e ) {
            e.printStackTrace( ) ;
        } // Catch
        return null;
    } // getDocument

e o que tenho de retorno não e no mesmo, ele vem de outra maneira...

Eu queria estar manipulando isso de modo que eu tivesse a saída assim

Sao Paulo/Congonhas Aeroporto, Brazil (SBSP) 23-37S 046-39W 802M
Jan 18, 2008 - 02:00 PM EST / 2008.01.18 1900 UTC
from the NNW (340 degrees) at 15 MPH (13 KT):0 Wind;
greater than 7 mile(s):0
mostly cloudy
78 F (26 C)
66 F (19 C)
65%
29.91 in. Hg (1013 hPa)

Ou talvez a questão seja como eu manipulo XML a partir de um URL http://www.webservicex.com/globalweather.asmx/GetWeather?CityName=Sao%20Paulo&CountryName=Brazil
Valeu

1 Resposta

marciocamurati

Cara,

Você já está recuperando o XML no InputStream agora resta apenas parsear a resposta dele, utilizando DOM4J http://www.dom4j.org/ por exemplo.

[]s

Criado 18 de janeiro de 2008
Ultima resposta 18 de jan. de 2008
Respostas 1
Participantes 2