Ryan Erdmann
Ryan Erdmann

Reputation: 11

Use Flash E4X with Bing

I'm using Action Script 3.0, and am using E4X to parse some XML files. It was working fine, until I began using Bing's xml result file.

Here's a sample of Bing's XML result:

<web:Web xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web">
    <web:Total>85700000</web:Total>
    <web:Offset>0</web:Offset>
    <web:Results>
      <web:WebResult>
        <web:Title>HELLO! - The place for celebrity news - hellomagazine.com</web:Title>

I need to get info from the WebResult node, but the colon in the web:WebResult is throwing me off.

I've tried the following:

var title:String = xml..Results.WebResult[0].text();

to get the first title from the Web Results, but it doesn't work. I think that it can't find the WebResult node because this returns 0

var results:int = xml..Results.WebResult.length();

Any suggestions on how to get information from this kind of XML file using E4X? Thanks!

Upvotes: 0

Views: 70

Answers (1)

Ryan Erdmann
Ryan Erdmann

Reputation: 11

I found the answer: First, define the namespace variable 'web' by writing this

var xhtml:Namespace = new Namespace("schemas.microsoft.com/LiveSearch/2008/04/XML/web";); 

Then, add 'web::' before each element in the E4X expression. For example,

xml..Results.WebResult.length(); 

becomes

xml..web::Results.web::WebResult.length();

Upvotes: 1

Related Questions