Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732

    leggere un file xml (yahoo weather)

    'giorno...

    sto tentando di leggere un file xml:
    http://xml.weather.yahoo.com/forecastrss?p=ITXX0113&u=c

    in particolare, avrei bisogno di ottenere i valori di

    <yweather:condition text="Partly Cloudy" code="30" temp="30" date="Mon, 04 Aug 2008 4:50 pm CEST" />
    <yweather:forecast day="Mon" date="4 Aug 2008" low="21" high="31" text="Mostly Clear" code="33" />
    <yweather:forecast day="Tue" date="5 Aug 2008" low="22" high="31" text="Mostly Sunny" code="34" />

    tutto il resto non mi interessa

    ho provato con simplexml, ma sembra che mi estrapoli solo una parte dell'xml.. e nemmeno quella che mi interessa:

    codice:
    SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [version] => 2.0
            )
    
        [channel] => SimpleXMLElement Object
            (
                [title] => Yahoo! Weather - Cuneo, IT
                [link] => http://us.rd.yahoo.com/dailynews/rss...TXX0113_c.html
                [description] => Yahoo! Weather for Cuneo, IT
                [language] => en-us
                [lastBuildDate] => Mon, 04 Aug 2008 4:50 pm CEST
                [ttl] => 60
                [image] => SimpleXMLElement Object
                    (
                        [title] => Yahoo! Weather
                        [width] => 142
                        [height] => 18
                        [link] => http://weather.yahoo.com
                        [url] => http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif
                    )
                [item] => SimpleXMLElement Object
                    (
                        [title] => Conditions for Cuneo, IT at 4:50 pm CEST
                        [link] => http://us.rd.yahoo.com/dailynews/rss...TXX0113_c.html
                        [pubDate] => Mon, 04 Aug 2008 4:50 pm CEST
                        [description] => SimpleXMLElement Object
                            (
                            )
                        [guid] => ITXX0113_2008_08_04_16_50_CEST
                    )
            )
    )
    vorrei evitare espressioni regolari et similia, mi piacerebbe prendere le stringhe utilizzando un parser xml... come posso fare?


  2. #2
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    Prova a dare un occhio a questa classe:

    http://magpierss.sourceforge.net/

    ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    398
    E' evidente che il simpleXml ha dei seri problemi con i namespaces.

    C'e' un modo orrendo ma veloce che e' quello di fare un replace string di yweather: con
    tipo yweather cosi elimini lo space name e dopo hai dei campi cosi

    <yweatherlocation city="Cuneo" region="" country="IT"/>
    <yweatherunits temperature="C" distance="km" pressure="mb" speed="kph"/>
    <yweatherwind chill="19" direction="230" speed="8.05" />
    <yweatheratmosphere humidity="88" visibility="9.99" pressure="0" rising="0" />
    <yweatherastronomy sunrise="6:22 am" sunset="8:49 pm"/>


    Un altro piu elegante e corretto e' quello di usare le librerie DOM al posto del simpleXml

    Andrea

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.