在一个XML文件中选择特定的数据

编程入门 行业动态 更新时间:2024-10-26 16:28:10
本文介绍了在一个XML文件中选择特定的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个xml文件

<data-set xmlns:xsi="www.w3/2001/XMLSchema-instance"> <record> <Date>1 July</Date> <Ville>New-York</Ville> <haute>6h50</haute> <basse>1h14</basse> <haute2>20h01</haute2> <basse2>13h16</basse2> </record> <record> <Date>2 July</Date> <Ville>New-York</Ville> <haute>7h36</haute> <basse>1h59</basse> <haute2>20h41</haute2> <basse2>13h56</basse2> </record> <record> <Date>3 July</Date> <Ville>Miami</Ville> <haute>8h21</haute> <basse>2h44</basse> <haute2>21h22</haute2> <basse2>14h37</basse2> </record> </data-set>

我想,在我的AS3 code,才能够从这个XML文件中选择特定的数据。

I would like, in my AS3 code, to be able to select specific data from this xml file.

例如:

var currentDate=new Date(); var day=currentDate.getDate(); If the day == one of the day of the xml, display "haute" of the corresponding day.

这可能吗?我该怎么办呢?

Is it possible ? How can I do that ?

推荐答案

您可以做你正在寻找通过过滤由属性或元素的XML数据,了解更多详情什么看一看此处。

You can do what you are looking by filtering your xml data by attribute or element, for more details take a look here.

因此​​,对于你的例子,你可以这样做:

So for you example, you can do like this :

var xml:XML = <data-set xmlns:xsi="www.w3/2001/XMLSchema-instance"> <record> <Date>1 July</Date> <Ville>New-York</Ville> <haute>6h50</haute> <basse>1h14</basse> <haute2>20h01</haute2> <basse2>13h16</basse2> </record> <record> <Date>2 July</Date> <Ville>New-York</Ville> <haute>7h36</haute> <basse>1h59</basse> <haute2>20h41</haute2> <basse2>13h56</basse2> </record> <record> <Date>3 July</Date> <Ville>Miami</Ville> <haute>8h21</haute> <basse>2h44</basse> <haute2>21h22</haute2> <basse2>14h37</basse2> </record> </data-set> ; var search:XMLList = xml.record.(Date == '3 July'); if(search){ trace(search.haute); // gives : 8h21 }

和从外部文件加载数据时:

And when loading data from an external file :

var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, on_xml_loaded); loader.load(new URLRequest('xml.xml')); function on_xml_loaded(e:Event){ var xml:XML = new XML(e.target.data); var search:XMLList = xml.record.(Date == '3 July'); if(search){ trace(search.haute); // gives : 8h21 } }

希望能有所帮助。

Hope that can help.

更多推荐

在一个XML文件中选择特定的数据

本文发布于:2023-10-17 06:14:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   数据   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!