在一个XML文件中选择特定的数据 [英] select specific data in a xml file
本文介绍了在一个XML文件中选择特定的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个xml文件
<data-set xmlns:xsi="http://www.w3.org/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数据,了解更多详情什么看一看<一个href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e6b.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7e60"相对=nofollow>此处。
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="http://www.w3.org/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文件中选择特定的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文