如何显示节点的XML后代在AS3特定的属性? [英] How do I display XML descendants of a node with a specific attribute in AS3?

查看:186
本文介绍了如何显示节点的XML后代在AS3特定的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何显示后代(在这种情况下exchangeRate和PlacesOfInterest)父节点的具有特定属性。

上一个按钮,设置一个字符串变量到目的地,例如用户点击 -

要设置场景。日本和澳大利亚。

在code,然后通过在XML中一组节点上运行任何具有匹配属性被跟踪 - 很简单

我想不通的是,如何在显示与该属性节点的唯一的子节点。

我敢肯定,必须有这样做的方式,我可能会被敲我的头靠在桌子时,我发现它,但任何帮助将是很大的AP preciated!

 公共职能ParseDestinations(destinationInput:XML):无效
    {
        VAR destAttributes:返回XMLList = destinationInput.adventure.destination.attributes();

        每个(VAR destLocation:XML在destAttributes)
        {
            如果(destLocation ==了destname){
                跟踪(destLocation);
                跟踪(destinationInput.adventure.destination.exchangeRate.text());
            }
        }
    }



<目的地>
    <冒险>
        <目标位置=日本>
            &其中; exchangeRate> 400℃/ exchangeRate>
            < placesOfInterest>武士历史和LT; / placesOfInterest>
        < /目的>
        <目标位置=澳大利亚>
            &其中; exchangeRate> 140℃; / exchangeRate>
            < placesOfInterest>冲浪和BBQ< / placesOfInterest>
        < /目的>
    < /冒险>
< /目的地>
 

解决方案

您应该能够很容易地筛选节点使用E4X在AS3:

  VAR目的地:XML =<目的地>
    <冒险>
        <目标位置=日本>
            &其中; exchangeRate> 400℃/ exchangeRate>
            < placesOfInterest>武士历史和LT; / placesOfInterest>
        < /目的>
        <目标位置=澳大利亚>
            &其中; exchangeRate> 140℃; / exchangeRate>
            < placesOfInterest>冲浪和BBQ< / placesOfInterest>
        < /目的>
    < /冒险>
< /目的地取代;
//按属性名过滤器
VAR filteredByLocation:返回XMLList = destinations.adventure.destination(@位置==日本制造);
跟踪(filteredByLocation);
//通过节点值滤波
VAR filteredByExchangeRate:返回XMLList = destinations.adventure.destination(exchangeRate< 200);
跟踪(filteredByExchangeRate);
 

有一个看雅虎DEVNET文章罗杰的E4X文章更多细节。

相关计算器问题:

  • <一个href="http://stackoverflow.com/questions/3223168/select-xml-nodes-by-attribute-in-as3/3223194#3223194">Select在AS3属性的XML节点
  • <一个href="http://stackoverflow.com/questions/3612624/a-question-about-parsing-xml-file-in-flex/3612913#3612913">a有关解析XML文件中的Flex
  • 问题

心连心

I've been trying to figure out how to display the descendants (in this case exchangeRate and PlacesOfInterest) of a parent node with a specific attribute.

To set the scene - the user clicks on a button which sets a string variable to a destination eg. japan or australia.

The code then runs through a set of nodes in the XML and any that have a matching attribute is traced - simple enough

What I can't figure out is how to then display only the child nodes of the node with that attribute.

I'm sure there has to be a way of doing it and I'll probably be banging my head against the desk when I find it, but any help would be greatly appreciated!

public function ParseDestinations(destinationInput:XML):void 
    {
        var destAttributes:XMLList = destinationInput.adventure.destination.attributes();

        for each (var destLocation:XML in destAttributes) 
        {               
            if (destLocation == destName){
                trace(destLocation);
                trace(destinationInput.adventure.destination.exchangeRate.text());
            }
        }
    }



<destinations>
    <adventure>
        <destination location="japan">
            <exchangeRate>400</exchangeRate>
            <placesOfInterest>Samurai History</placesOfInterest>
        </destination>   
        <destination location="australia">
            <exchangeRate>140</exchangeRate>
            <placesOfInterest>Surf and BBQ</placesOfInterest>
        </destination>
    </adventure>
</destinations>

解决方案

You should be able to easily filter nodes with E4X in as3:

 var destinations:XML = <destinations>
    <adventure>
        <destination location="japan">
            <exchangeRate>400</exchangeRate>
            <placesOfInterest>Samurai History</placesOfInterest>
        </destination>   
        <destination location="australia">
            <exchangeRate>140</exchangeRate>
            <placesOfInterest>Surf and BBQ</placesOfInterest>
        </destination>
    </adventure>
</destinations>;
//filter by attribute name
var filteredByLocation:XMLList = destinations.adventure.destination.(@location == "japan");
trace(filteredByLocation);
//filter by node value
var filteredByExchangeRate:XMLList = destinations.adventure.destination.(exchangeRate < 200);
trace(filteredByExchangeRate);

Have a look at the Yahoo! devnet article or Roger's E4X article for more details.

Related stackoverflow questions:

HTH

这篇关于如何显示节点的XML后代在AS3特定的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆