Comunidad de diseño web y desarrollo en internet online

Como leo este formato XML con as3 ?

Citar            
MensajeEscrito el 26 Abr 2012 08:55 pm
Saludos ActionScripTianos();

Necesito leer ciertos atributos de esta estructura xml:

Código XML :

etc...
<yweather:location xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" city="La Paz" country="BL" region=""/>
<yweather:units xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" distance="mi" pressure="in" speed="mph" temperature="F"/>
<yweather:wind xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" chill="57" direction="270" speed="15"/>

<yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="29" date="26 Apr 2012" day="Thu" high="58" low="35" text="Partly Cloudy"/>
<yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="39" date="27 Apr 2012" day="Fri" high="58" low="31" text="PM Showers"/>
...etc


Lo que quiero es obtener los valores de:
"city" de la etiqueta <yweather:location ....../>
"xmlns:yweather" de la etiqueta <yweather:forecast ....../>

Espero pudan ayudarme, ya que todo lo demas si lo entiendo, gracias.

Por WWCC

113 de clabLevel



Genero:Masculino  

Diseñador y desarrollador multimedia

chrome
Citar            
MensajeEscrito el 27 Abr 2012 08:03 am
supongamos que el contenedor del xml es una variable llamado "xmlContenedor"

entonces

Código ActionScript :

for each (var Valor: XML in xmlContenedor.elements())
{
   if (Valor.attribute("city").toString()) trace(Valor.attribute("city"));
   
   if (Valor.localName()=="forecast") trace(Valor.namespace());

   trace("--------------");
}

espero que te sirva y te solucione tus dudas

saludos

Por Yonomimi

76 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 28 Abr 2012 02:52 pm
Gracias por tu respuesta... lo de namespace() no me lo sabia ¬¬ #
Al final lo resolví así:
[AS3]
private function xmlCargado(e:Event):void
{
clima_xml = new XML(e.target.data);
var lista1:XMLList = clima_xml.results.channel.elements();
_ciudad = String(lista1[6].@city)
var lista2:XMLList = clima_xml.results.channel.item.elements();
_recurso = String(lista2[7].namespace());
}
[/AS3]
por cierto mi xml completo era este.....

Código XML :

<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
    yahoo:count="1" yahoo:created="2012-04-25T00:35:30Z" yahoo:lang="en-US">
    <results>
        <channel>
            <title>Yahoo! Weather - Viacha, BL</title>
            <link>http://us.rd.yahoo.com/dailynews/rss/weather/Viacha__BL/*http://weather.yahoo.com/forecast/BLXX0018_f.html</link>
            <description>Yahoo! Weather for Viacha, BL</description>
            <language>en-us</language>
            <lastBuildDate>Tue, 24 Apr 2012 8:02 pm BOT</lastBuildDate>
            <ttl>60</ttl>
            <yweather:location
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                city="Viacha" country="BL" region=""/>
            <yweather:units
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                distance="mi" pressure="in" speed="mph" temperature="F"/>
            <yweather:wind
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                chill="41" direction="250" speed="7"/>
            <yweather:atmosphere
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                humidity="81" pressure="30.56" rising="0" visibility="4.97"/>
            <yweather:astronomy
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                sunrise="6:44 am" sunset="6:19 pm"/>
            <image>
                <title>Yahoo! Weather</title>
                <width>142</width>
                <height>18</height>
                <link>http://weather.yahoo.com</link>
                <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
            </image>
            <item>
                <title>Conditions for Viacha, BL at 8:02 pm BOT</title>
                <geo:lat xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">-16.65</geo:lat>
                <geo:long xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">-68.3</geo:long>
                <link>http://us.rd.yahoo.com/dailynews/rss/weather/Viacha__BL/*http://weather.yahoo.com/forecast/BLXX0018_f.html</link>
                <pubDate>Tue, 24 Apr 2012 8:02 pm BOT</pubDate>
                <yweather:condition
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="11" date="Tue, 24 Apr 2012 8:02 pm BOT"
                    temp="45" text="Light Rain"/>
                <description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/11.gif"/><br />
<b>Current Conditions:</b><br />
Light Rain, 45 F<BR />
<BR /><b>Forecast:</b><BR />
Tue - Showers. High: 54 Low: 38<br />
Wed - AM Showers. High: 59 Low: 36<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Viacha__BL/*http://weather.yahoo.com/forecast/BLXX0018_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="11" date="24 Apr 2012" day="Tue" high="54"
                    low="38" text="Showers"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="39" date="25 Apr 2012" day="Wed" high="59"
                    low="36" text="AM Showers"/>
                <guid isPermaLink="false">BLXX0018_2012_04_25_7_00_BOT</guid>
            </item>
        </channel>
    </results>
</query>

Por WWCC

113 de clabLevel



Genero:Masculino  

Diseñador y desarrollador multimedia

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.