Adobe Dreamweaver Forums



Last 10 THreads :         static sound (Last Post : kglad - Replies : 11 - Views : 12 )           »          Code that can effect two movie clips (Last Post : Alessandroy - Replies : 2 - Views : 3 )           »          load xml into mc symbols (Last Post : kglad - Replies : 1 - Views : 2 )           »          Adobe Flash 10 kills Wimpy (Last Post : midiwriter - Replies : 83 - Views : 955 )           »          Create 2nd animation in same flash file (Last Post : dabooj - Replies : 0 - Views : 1 )           »          Local host and php Solutions help... (Last Post : RJweb - Replies : 1 - Views : 6 )           »          problems linking PDFs (Last Post : Alan - Replies : 3 - Views : 4 )           »          Flash movie not working in html (Last Post : WEBDavid - Replies : 0 - Views : 1 )           »          drop down menu over flash (Last Post : ltartisel - Replies : 2 - Views : 3 )           »          Flash-PHP Mail Form (Last Post : kglad - Replies : 3 - Views : 4 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-25-2008, 05:33 AM
pranay.kondekar@gmail.com
 
Posts: n/a
Diggs:
Default Retrieving data from XML containing namespaces?

Hi,
I am using Yahoo Local Search Service which returns the XML response. I want
to retrieve data from the XML that I received. I stuck at this point and unable
to retrieve the response in to datagrid. Does the namespaces in XML matter
while retrieving data?
The response XML is as follows

<ResultSet xsi:schemaLocation="urn:yahoo:lcl
http://api.local.yahoo.com/LocalSearchService/V3/L ocalSearchResponse.xsd"
totalResultsAvailable="224" totalResultsReturned="1" firstResultPosition="1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:lcl">

<ResultSetMapUrl>http://maps.yahoo.com/broadband/?q1=...A+95112&amp;tt
=starbucks&amp;tp=1</ResultSetMapUrl>
<Result id="21590724">
<Title>Starbucks</Title>
<Address>145 W Santa Clara St</Address>
<City>San Jose</City>
<State>CA</State>
<Phone>(408) 288-8803</Phone>
<Latitude>37.335236</Latitude>
<Longitude>-121.892765</Longitude>
<Rating>
<AverageRating>4</AverageRating>
<TotalRatings>3</TotalRatings>
<TotalReviews>2</TotalReviews>
<LastReviewDate>1198029377</LastReviewDate>
<LastReviewIntro>My previous review had incorrect data. That was not
true, I am sorry, I didn't know. As far as food and drink goes, Starbucks is
pretty good.</LastReviewIntro>
</Rating>
<Distance>0.96</Distance>
<Url>http://local.yahoo.com/info-21590724-starbucks-san-jose</Url>

<ClickUrl>http://local.yahoo.com/info-21590724-starbucks-san-jose</ClickUrl>

<MapUrl>http://maps.yahoo.com/maps_result?q1...San+Jose+CA&am
p;gid1=21590724</MapUrl>
<BusinessUrl>http://www.starbucks.com/</BusinessUr l>
<BusinessClickUrl>http://www.starbucks.com/</Busin essClickUrl>
<Categories>
<Category id="96926219">Cafes</Category>
<Category id="96926236">Restaurants</Category>
<Category id="96926169">Coffee Houses</Category>
</Categories>
</Result>
</ResultSet>

The code that I am writing to get Title and Address is as follows.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundAlpha="0" backgroundColor="#FFFFFF">

<mx:HTTPService
id="weatherService"
url="http://local.yahooapis.com/LocalSearchService/ V3/localSearch"
resultFormat="e4x"
result="resultHandler(event);"/>

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;

[Bindable]
private var myResult:XML ;
private var temp:XMLNode;
private var list:ArrayCollection;

public function requestWeather():void {
weatherService.cancel();
var params:Object = new Object();
params.appid = "YahooDemo";
params.query = "starbucks";
params.zip = "95112";
params.results = "1"
weatherService.send(params);
}

public function resultHandler(event:ResultEvent):void {
myResult = XML( event.result);
temp = myResult.Result;
list = ArrayCollection(event.result);
}
]]>
</mx:Script>

<mx:Form width="400">
<mx:FormItem label="Get Local Data">
<mx:Button label="Get Data" click="requestWeather();"/>
</mx:FormItem>
<mx:FormItem label="Address">
<mx:Text text="{myResult.Result.Address}"/>
</mx:FormItem>
<mx:FormItem label="Title">
<mx:Text text="{myResult.Result.Title}"/>
</mx:FormItem>
</mx:Form>

<mxataGrid
dataProvider="{myResult.Result}"
x="80" y="141" width="262" height="92" id="shippingOptionsList"
editable="false" enabled="true">
<mx:columns>
<mxataGridColumn headerText="Title" dataField="Title" />
<mxataGridColumn headerText="Address" dataField="Address" />
</mx:columns>
</mxataGrid>
<mx:Label text="Response as it is"/>
<mx:TextArea id="resultFld" text="{myResult}" width="400" height="152"/>


</mx:Application>


Can somebody help me to find where I am going wrong?

Thank you
-Pranay





Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-25-2008, 11:53 AM
Sam Rowe
 
Posts: n/a
Diggs:
Default Re: Retrieving data from XML containing namespaces?

Hi Pranay,

It looks like your problem is indeed to do with the XML namespace being used.

Try adding this line after the import statements:

namespace yahoo = "urn:yahoo:lcl";

(This is the namespace URI defined in the returned XML)

The result handler should then look like this:

public function resultHandler(event:ResultEvent):void {
use namespace yahoo;
myResult = XML( event.result);
temp = myResult.Result;
list = ArrayCollection(event.result);
}


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:59 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk