如何构建 E4X 语法来处理属性?

发布于 2024-11-06 18:12:21 字数 1111 浏览 4 评论 0原文

我正在使用 Wea​​ther.com XML Web 服务来获取预报的高温、低温和图标。 XML 片段如下:

<dayf>
<lsup>5/14/11 2:21 AM Local Time</lsup> 
<day d="0" t="Saturday" dt="May 14">
<hi>63</hi> 
<low>48</low> 
<sunr>6:39 AM</sunr> 
<suns>5:04 PM</suns> 
<part p="d">
<icon>32</icon> 

我尝试使用以下脚本片段跟踪上述节点和属性:

XML.ignoreWhitespace = true;
var urlLoader:URLLoader = event.currentTarget as URLLoader;
var resultXML:XML = XML(urlLoader.data);
trace(resultXML.dayf.day.hi);
trace(resultXML.dayf.day.low);
trace(resultXML.dayf.day.part.attribute("p=d").icon);

lbllowtemp.text= String(resultXML.dayf.day.low);
lblhitemp.text=String(resultXML.dayf.day.hi);
uicondicon.source=String(resultXML.dayf.day.part.attribute("p=d").icon)+".png";

但是,当我在 Flash 应用程序中运行此脚本时,我收到:

Error #2044: Unhandled ioError:. text=Error #2035: URL Not Found. URL: file:///C|/Documents/WeatherFLV/.png

因此,正在读取 hi 和 low 值,但是属性 p=d 的节点部分中的图标值不起作用。

我应该如何修改 E4X 语法来获取图标节点?

非常感谢!

I'm using the weather.com XML web service to get the forecast high temp, low temp and icon. The XML snippet is as follows:

<dayf>
<lsup>5/14/11 2:21 AM Local Time</lsup> 
<day d="0" t="Saturday" dt="May 14">
<hi>63</hi> 
<low>48</low> 
<sunr>6:39 AM</sunr> 
<suns>5:04 PM</suns> 
<part p="d">
<icon>32</icon> 

I'm attempting to trace the above nodes and attributes using the following script snippet:

XML.ignoreWhitespace = true;
var urlLoader:URLLoader = event.currentTarget as URLLoader;
var resultXML:XML = XML(urlLoader.data);
trace(resultXML.dayf.day.hi);
trace(resultXML.dayf.day.low);
trace(resultXML.dayf.day.part.attribute("p=d").icon);

lbllowtemp.text= String(resultXML.dayf.day.low);
lblhitemp.text=String(resultXML.dayf.day.hi);
uicondicon.source=String(resultXML.dayf.day.part.attribute("p=d").icon)+".png";

However, when I run this script in my Flash application, I receive:

Error #2044: Unhandled ioError:. text=Error #2035: URL Not Found. URL: file:///C|/Documents/WeatherFLV/.png

So, the hi and low values are being read but the icon value in node part with attribute p=d is not working.

How should I modify my E4X syntax to obtain the icon node?

Thanks much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心欲静而疯不止 2024-11-13 18:12:21

属性名称是 'p' 而不是 'p=d',属性 p 的值为 "d"< /代码>。
因此,您想要在 标记中查找具有属性 p 且值为 "d" 的图标节点。

.(xxxxx) 将使用给定条件过滤您的 XML,这里 @p 是属性,

如果您只有一个具有这样的值的部分,您可以这样做:

resultXML.dayf.day.part.(@p=="d").icon

否则,如果您有多个值你可以获得第一条记录:

resultXML.dayf.day.part.(@p=="d")[0].icon

The attribute name is 'p' and not 'p=d', and the value of attribute p is "d".
So you want to find the icon node within a <part> tag with an attribute p who has the value "d".

.(xxxxx) will filter your XML with a given condition, here @p is the attribute

if you have only one part with such a value you can do:

resultXML.dayf.day.part.(@p=="d").icon

otherwise if you have multiple value you can get the first record:

resultXML.dayf.day.part.(@p=="d")[0].icon
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文