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开发者_Python百科 using E4X? Thanks!
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();
精彩评论