我使用Action script3.0,并使用E4X来解析一些XML文件。在我开始使用Bing的xml结果文件之前,它一直工作得很好。
以下是Bing的XML结果示例:
<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>我需要从WebResult节点获取信息,但是web中的冒号WebResult让我抓狂了。
我尝试过以下几种方法:
var title:String = xml..Results.WebResult[0].text();从Web结果中获取第一个标题,但它不起作用。我认为它找不到WebResult节点,因为它返回0
var results:int = xml..Results.WebResult.length();关于如何使用E4X从这种XML文件中获取信息,有什么建议吗?谢谢!
发布于 2011-03-20 13:32:36
我找到了答案:首先,通过编写以下代码来定义名称空间变量'web‘
var xhtml:Namespace = new Namespace("schemas.microsoft.com/LiveSearch/2008/04/XML/web";); 然后,在E4X表达式中的每个元素之前添加“web::”。例如,
xml..Results.WebResult.length(); 变成了
xml..web::Results.web::WebResult.length();https://stackoverflow.com/questions/5366805
复制相似问题