Solved

rdf:RDF XML in Flex DataGrid

Posted on 2007-11-21
13
562 Views
Last Modified: 2008-02-01
I am trying to code a flex application to show an rss feed.  
the feed looks like this
<?xml version="1.0" encoding="ISO-8859-1"?>

<rdf:RDF
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<item rdf:about="">
<title>Christmas! </title>
<link>http://somelink.com</link>
</item>
</rdf:RDF>

i tried using
dataProvider="{cl.lastResult.rdf.item}"

to populate my datagrid but it is not populating

i think the rdf:RDF is screwing something up
0
Comment
Question by:jduawa
  • 8
  • 4
13 Comments
 
LVL 1

Author Comment

by:jduawa
ID: 20328730
here iss my datagrid
<mx:DataGrid x="32" y="184" width="702" height="288" dataProvider="{cl.lastResult.rdf.item}">

		<mx:columns>
 

			<mx:DataGridColumn headerText="Post Title" dataField="title"/>

			<mx:DataGridColumn headerText="Link" dataField="link"/>

		</mx:columns>

	</mx:DataGrid>

Open in new window

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 20329238
Try

dataProvider="{cl.lastResult..item}"
0
 
LVL 1

Author Comment

by:jduawa
ID: 20329332
that is the complete code...i changed it up a little bit after looking at some examples but it still isnt working...
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

	<mx:Script>

		<![CDATA[

			import mx.rpc.events.ResultEvent;

			import mx.rpc.events.FaultEvent;

			import mx.controls.Alert;

			

			[Bindable]

			public var clURL:String;

			public var clResults:XML;

			

			public function setURL(city:String):String{

				this.clURL="http://"+city+".craigslist.org/search/sss?query="+clSearchStr.text+"&format=rss";

				//Alert.show(clURL);

				return this.clURL;

			}

			

	        public function handleXML(event:ResultEvent):void

            {

               clResults = event.result as XML;

               this.t.text=clResults.toString();

            }
 

	        public function handleFault(event:FaultEvent):void

	        {

	           Alert.show(event.fault.faultString, "Error");

	        }

		]]>

	</mx:Script>

	<mx:HTTPService id="craigslist_xml" url="{clURL}" resultFormat="e4x" showBusyCursor="true" result="handleXML(event);" fault="handleFault(event);"/>

	<mx:Label x="32" y="27" text="Search Term" id="L1" enabled="true"/>

	<mx:TextInput x="115" y="25" id="clSearchStr"/>

	<mx:Button x="32" y="144" label="Search" id="B1" click="craigslist_xml.send()" />

	<mx:CheckBox x="32" y="66" label="Denver" id="denver" click="setURL(this.denver.id)"/>

	<mx:CheckBox x="32" y="92" label="Chicago" id="chicago" click="setURL(this.chicago.id)"/>

	<mx:CheckBox x="32" y="118" label="Portland" id="portland" click="setURL(this.portland.id)"/>

	<mx:DataGrid x="32" y="184" width="702" height="288" dataProvider="{clResults}">

		<mx:columns>

			<mx:DataGridColumn headerText="Post Title" dataField="title"/>

			<mx:DataGridColumn headerText="Link" dataField="link"/>

		</mx:columns>

	</mx:DataGrid>

	<mx:TextArea x="301" y="10" width="433" height="166" id="t" wordWrap="true" editable="true" enabled="true" />

</mx:Application>

Open in new window

0
 
LVL 1

Author Comment

by:jduawa
ID: 20329356
ideally i  would like for the user to be able to click multiple locations and append the results to the datagrid.  I am just learning Flex so alot of this is new to me.
Thanks
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 20329498
Scanning the rss output it looks like you should change your DP to:
dataProvider="{craigslist_xml.lastResult.rdf:RDF.item}"

This thread has a working rss reader, it also solves the security problem:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Flex/Q_22910937.html
0
 
LVL 1

Author Comment

by:jduawa
ID: 20329500
the compiler didnt like the rdf:RDF when i tried it
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
ID: 20330000
Here is working source, amongst other things the rss feed with the search you were calling was returning html so you'll have to check that

Regards
Gary
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

	<mx:Script>

		<![CDATA[

			import mx.rpc.events.ResultEvent;

			import mx.rpc.events.FaultEvent;

			import mx.controls.Alert;

			

			[Bindable]

			public var clURL:String;

			[Bindable]

			public var clResults:Object;

			

			public function setURL(city:String):String{

				this.clURL="http://"+city+".craigslist.org/sss/index.rss";

				//Alert.show(clURL);

				return this.clURL;

			}

			

	        public function handleXML(event:ResultEvent):void

            {

               clResults = event.result.RDF.item;

               this.t.text=clResults.toString();

            }

 

	        public function handleFault(event:FaultEvent):void

	        {

	           Alert.show(event.fault.faultString, "Error");

	        }

		]]>

	</mx:Script>

	<mx:HTTPService id="craigslist_xml" url="{clURL}" resultFormat="object" showBusyCursor="true" result="handleXML(event);" fault="handleFault(event);"/>

	<mx:Label x="32" y="27" text="Search Term" id="L1" enabled="true"/>

	<mx:TextInput x="115" y="25" id="clSearchStr"/>

	<mx:Button x="32" y="144" label="Search" id="B1" click="craigslist_xml.send()" />

	<mx:CheckBox x="32" y="66" label="Denver" id="denver" click="setURL(this.denver.id)"/>

	<mx:CheckBox x="32" y="92" label="Chicago" id="chicago" click="setURL(this.chicago.id)"/>

	<mx:CheckBox x="32" y="118" label="Portland" id="portland" click="setURL(this.portland.id)"/>

	<mx:DataGrid x="32" y="184" width="702" height="288" dataProvider="{clResults}">

		<mx:columns>

			<mx:DataGridColumn headerText="Post Title" dataField="title"/>

			<mx:DataGridColumn headerText="Link" dataField="link"/>

		</mx:columns>

	</mx:DataGrid>

	<mx:TextArea x="301" y="10" width="433" height="166" id="t" wordWrap="true" editable="true" enabled="true" />

</mx:Application>

Open in new window

0
 
LVL 1

Author Comment

by:jduawa
ID: 20330076
what you provided is for the rss.
what i am looking for is the rss of the resulting search from craigslist.
which is not the URL you are using.

when i use
this.clURL="http://"+city+"craigslist.org/search/sss?query="+this.clSearchStr.text+"&format=rss";

i get an XML parser error
0
 
LVL 1

Author Comment

by:jduawa
ID: 20330093
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 20332877
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
            <![CDATA[
                  import mx.utils.StringUtil;
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.events.FaultEvent;
                  import mx.controls.Alert;
                  
                  [Bindable]
                  public var clResults:Object;
                  
                  public function go():void
                  {
                        this.clSearchStr.text = mx.utils.StringUtil.trim(this.clSearchStr.text);
                        if( this.clSearchStr.text.length == 0)
                          Alert.show("Enter a search phrase", "Search");                              
                        else
                        {
                              craigslist_xml.url = "http://" + svrGrp.selectedValue + ".craigslist.org/search/sss?query=" + encodeURI( this.clSearchStr.text) + "&format=rss";
                              craigslist_xml.send();
                        }
                  }
                  
              public function handleXML(event:ResultEvent):void
            {
                  try
                  {
                        if( event.result.RDF.item == null)
                        {
                              clResults = null;                              
                                    Alert.show("Your query returned no results", "Search");                              
                        }
                        else
                        {
                                 clResults = event.result.RDF.item;
                                      this.t.text=clResults.toString();
                        }
                   }
                   catch( e:*)
                   {
                         this.t.text = e.message;
                   }            
            }
              public function handleFault(event:FaultEvent):void
              {
                 Alert.show(event.fault.faultString + "\r\n" + craigslist_xml.url, "Error");
              }
            ]]>
      </mx:Script>
      <mx:HTTPService id="craigslist_xml" concurrency="last" resultFormat="object" showBusyCursor="true" result="handleXML(event);" fault="handleFault(event);"/>
      <mx:Label x="32" y="27" text="Search Term" id="L1" enabled="true"/>
      <mx:TextInput x="115" y="25" id="clSearchStr"/>
      <mx:Button x="32" y="144" label="Search" id="B1" click="go()" />
      <mx:RadioButtonGroup id="svrGrp"/>
      <mx:RadioButton x="32" y="66" selected="true" label="Denver" value="denver" groupName="svrGrp"/>
      <mx:RadioButton x="32" y="92" label="Chicago" value="chicago" groupName="svrGrp"/>
      <mx:RadioButton x="32" y="118" label="Portland" value="portland" groupName="svrGrp"/>
      <mx:DataGrid x="32" y="184" width="702" height="288" dataProvider="{clResults}">
            <mx:columns>
                  <mx:DataGridColumn headerText="Post Title" dataField="title"/>
                  <mx:DataGridColumn headerText="Link" dataField="link"/>
            </mx:columns>
      </mx:DataGrid>
      <mx:TextArea x="301" y="10" width="433" height="166" id="t" wordWrap="true" editable="true" enabled="true" />
</mx:Application>
0
 
LVL 1

Author Comment

by:jduawa
ID: 20336583
thanks.
0
 
LVL 1

Author Comment

by:jduawa
ID: 20336610
Why does that work and my code does not?  I am confused.  It looks to me like they are doing the same thing
0
 
LVL 19

Expert Comment

by:Gary Benade
ID: 20337453
They are doing the same thing, I just added error checking and bullet proofing, the xml from craiglists is invalid if there are no results for your query.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Difference between FDS and LCDS 7 341
Is this doable in Flex/AIR - pointers? 5 260
check for non negative number 2 442
Most efficient way of merging 2 ArrayCollections 4 880
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now