Extract strings from online XML
Posted: April 25th, 2011, 2:25 pm
Hi Folks,
I'm currently working in order to catch some online datas via an RSS feed. I use a Socket connection for this, which is working fine.
For example, here is the kind of datas I get in the RSS (it's a weather feed):
Please note that there are other "<meteo:weather" sections in the actual feed, the preview here is simplified. I'm attempting to get the second one, so I presume it would be indexed as "1" ("0" being the first, as always).
Let's assume I'm interested in getting the values into "tempe_matin". My code looks like this:
I've tried various options, using Namespace or not (anyway, I confess I'm not sure to understand perfectly what a Namespace is...
). Adobe's documentation just let me into the fog.
Could someone explain me my mistake(s) and how to extract a determined string from my XML object?
Thanks a lot for your help,
Julien
PS : Although my English may not be perfect, I hope it remains understandable
I'm currently working in order to catch some online datas via an RSS feed. I use a Socket connection for this, which is working fine.

For example, here is the kind of datas I get in the RSS (it's a weather feed):
Code: Select all
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0" xmlns:meteo="http://www.meteorologic.net/rss/1.0">
<channel><item>
<meteo:weather date="26 Avril" tempe_matin="10.4" namepictos_matin="Dégagé" pictos_matin="soleil" tempe_midi="18" namepictos_midi="Dégagé" pictos_midi="soleil" tempe_apmidi="21" namepictos_apmidi="Dégagé" pictos_apmidi="soleil" tempe_soir="16.4" namepictos_soir="Dégagé" pictos_soir="soleil" />
</item></channel></rss>
Let's assume I'm interested in getting the values into "tempe_matin". My code looks like this:
Code: Select all
// Creating an XML object from the String "xmlFinalString" got via Socket
try
{
var rss = new XML (xmlFinalString);
} catch(e) {
alert ("Impossible de formater les données recueillies en balises XML.\r " + e.toString());
break;
}
var ns = new Namespace ("meteo:weather");
var tempmatin = rss.ns[1].@tempe_matin.toString(); // Here ExtendScript crashes
alert (tempmatin);

Could someone explain me my mistake(s) and how to extract a determined string from my XML object?
Thanks a lot for your help,
Julien
PS : Although my English may not be perfect, I hope it remains understandable
