Foros del Web » Programación para mayores de 30 ;) » Java »

Ayuda Rss

Estas en el tema de Ayuda Rss en el foro de Java en Foros del Web. Hola, espero puedan ayudarme con esto...estoy tratando de rescatar los datos de un rss/xml de yahoo, que es el siguiente: http: //weather.yahooapis.com/forecastrss?w=2502265 y para ello ...
  #1 (permalink)  
Antiguo 24/11/2009, 09:31
Avatar de n_n
n_n
 
Fecha de Ingreso: noviembre-2009
Mensajes: 50
Antigüedad: 14 años, 5 meses
Puntos: 1
Exclamación Ayuda Rss

Hola, espero puedan ayudarme con esto...estoy tratando de rescatar los datos de un rss/xml de yahoo, que es el siguiente:

http:
//weather.yahooapis.com/forecastrss?w=2502265

y para ello estoy utilizando este codigo:

Código:
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class RSSReader {

    private String titulo;

    private static RSSReader instance = null;

    private RSSReader() {
    }

    public static RSSReader getInstance() {
        if (instance == null) {
            instance = new RSSReader();
        }
        return instance;
    }

    public void writeNews() {
        try {

            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            URL u = new URL("weather.yahooapis.com/forecastrss?w=349871&u=c");

            Document doc = builder.parse(u.openStream());

            NodeList nodosCanal = doc.getElementsByTagName("channel");

            NodeList nodosImg=  doc.getElementsByTagName("image");

            for (int i = 0; i < nodosCanal.getLength(); i++) {

                Element element = (Element) nodosCanal.item(i);

                
               System.out.println("*Title: " + element.getSchemaTypeInfo()+"**************");
                System.out.println("*Link: " + getElementValue(element, "link"));
            }//for
        }//try
        catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    private String getCharacterDataFromElement(Element e) {
        try {
            Node child = e.getFirstChild();
            if (child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            }
        } catch (Exception ex) {
        }
        return "";
    } //private String getCharacterDataFromElement

    protected float getFloat(String value) {
        if (value != null && !value.equals("")) {
            return Float.parseFloat(value);
        }
        return 0;
    }

    protected String getElementValue(Element parent, String label) {
        return getCharacterDataFromElement((Element) parent.getElementsByTagName(label).item(0));
    }

    public String getTitulo() {
        return titulo;
    }

public static void main(String[] args) {
		RSSReader reader = RSSReader.getInstance();
		reader.writeNews();
		}

}
pero mi problema es que no puedo rescatar los valores que son por ejemplo asi:

Código:
 <yweather:location city="Sunnyvale" region="CA" country="United States" />
o asi:

Código:
<yweather:condition text="Fair" code="33" temp="45" date="Tue, 24 Nov 2009 6:56 am PST" />
alguien me puede hechar una manito??

salu2
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:28.