如何构建 E4X 语法来处理属性?
我正在使用 Weather.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性名称是
'p'
而不是'p=d'
,属性p
的值为"d"< /代码>。
因此,您想要在
标记中查找具有属性p
且值为"d"
的图标节点。.(xxxxx)
将使用给定条件过滤您的 XML,这里@p
是属性,如果您只有一个具有这样的值的部分,您可以这样做:
否则,如果您有多个值你可以获得第一条记录:
The attribute name is
'p'
and not'p=d'
, and the value of attributep
is"d"
.So you want to find the icon node within a
<part>
tag with an attributep
who has the value"d"
..(xxxxx)
will filter your XML with a given condition, here@p
is the attributeif you have only one part with such a value you can do:
otherwise if you have multiple value you can get the first record: