views:

37

answers:

1

I'll try to ask this in a way that makes some sense.

I have an RSS feed, within Flex I have connected to the feed via HTTPService, the XML structure is as follows (not exact, but for the purpose of the question). I am able to walk down the xml and access the data within the title and link nodes with success but when I get the the description node and try to access the img and src attributes within it, I haven't had any success. Reading about parsing with e4x the example I get is:

var xList:XMLList = xData.channel.item.description.(attribute("src"));

or

var xList:XMLList = xData.channel.item.description.(@src);

I'm lost at this point, not sure where I go from here and would appreciate some direction at this point.

<rss>
<channel>
    <item>
        <title><![CDATA[some text]]></title>
        <link><![CDATA[a link]]></link>
        <description><![CDATA[<table border="0" cellpadding="8"><tr><td width="80px"><a href="http://anAddress"&gt;&lt;img border="0" src="http://anAddress.jpg"&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;someText&lt;/strong&gt;&lt;br&gt;someText&lt;br&gt;someText&lt;br&gt;&lt;a href="http://anAddress"&gt;someText&lt;/a&gt; | <a href="http://anAddress"&gt;someText&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;]]&gt;&lt;/description&gt;
    </item>
</channel>

<fx:Script>
    <![CDATA[

        [Bindable]
        private var xData:XML;

        import mx.events.FlexEvent;
        import mx.rpc.events.ResultEvent;

        protected function appCompleteHandler(event:FlexEvent):void{
            myService.send();
        }

        private function getList():void{
            var xList:XMLList = xData.channel.item.description;
            output.text = xList.toString();
        }

        private function rssResult(event:ResultEvent):void{
            xData = event.result as XML;
        }

    ]]>
</fx:Script>

    <s:controlBarContent>
    <s:Button label="Get List" click="getList()"/>
    <s:Button label="Change Data"/>
</s:controlBarContent>
<s:TextArea id="output" width="100%" height="100%"
    text="{xData.toString()}" fontSize="16"/>
A: 

It looks like it's the CDATA within the description node. Anything enclosed within CDATA is not parsed and just treated as text. If you have control over the data, you can try just getting rid of the CDATA tag. Otherwise you can re-parse the description text again doing something like:

var descXml:XML = new XML(xData.channel.item.description.toString());
trace(descXml..@src);

However, I'm seeing now the html content within the description is invalid which I guess is why the CDATA was thrown in there in the first place. If you have no control over that content (to close the img and br tags), you can try scraping for the src attribute with a little regex.

Dave