开发者

ActionScript 3 processing XML; == operator is returning empty XMLList

I have an xml document like the below one that I am trying to parse using AS3. I want to get all of the classes who have students playing Basketball. I thought that I could do something like:

var sport:String = "BasketBall";
var bbClasses:XMLList = xml.classes.class.(students.student.commitments.comm==sport);

Unfortionatly this is returning me an empty XMLList.

<master>
    <classes>

        <class>
            <classID>1</classID>
            <teacherID>66</teacherID>
            <students>
                <student>
                    <studentID>1</studentID>
                    <studentDescription>bla bla</studentDescription>
                    <commitments>
                        <comm>Hockey</comm>
                        <comm>Dance</comm>
                        &l开发者_JAVA百科t;comm>Basketball</comm>
                    </commitments>
                </student>
                <student>
                    <studentID></studentID>
                    <studentDescription>bla bla</studentDescription>
                    <commitments>
                        <comm>Hockey</comm>
                        <comm>Football</comm>
                        <comm>Basketball</comm>
                    </commitments>
                </student>
                <student>
                    ...
                </student>
                <student>
                    ...
                </student>
            </students>
        </class>
        <class>
            ...
        </class>    
        <class>
            ...
        </class>    
    </classes>
    <Commitments>
        ...
    </Commitments>
<master>


Use the contains method, rather than == operator.

var bbClasses:XMLList =
    xml.classes.class.(students.student.commitments.comm.contains(sport));

ps: Watch out for your case.

"BasketBall" ins't "Basketball", so your E4X won't match.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜