简体   繁体   English

Flex,XML和E4x

[英]Flex, xml and E4x

I have a basic question. 我有一个基本问题。 I am loading an XML file using the URLLoader and putting it into an XML variable. 我正在使用URLLoader加载XML文件,并将其放入XML变量中。

My question is, can i leverage E4x to go through this xml data. 我的问题是,我可以利用E4x浏览此xml数据吗?

I tried doing 我试着做

    for each (var grid in xmlData.grid){

        output.text=grid.name;

    }

But it says that variable 'grid' has no type declaration. 但是它说变量“ grid”没有类型声明。 This might make some sense since there is no way for the compiler to know before hand the structure of the XML that i am loading. 这可能是有道理的,因为编译器无法事先知道我正在加载的XML的结构。

But since i am new to AS3 and flex, i was wondering if there is a way of leveraging E4x? 但是由于我是AS3和Flex的新手,所以我想知道是否有一种利用E4x的方法?

Thanks 谢谢

You could type it anonymously (it would solve the problem): 您可以匿名输入(它将解决问题):

for each( var grid:* in xmlData.grid) {

but before you do that, consider these options here: 但在执行此操作之前,请先考虑以下选项:

// NOTE: This is a for...in, not a for each...in
for (var grid:XML in xmlData.grid){

    // This will give you the node name: 
    // <foo/> returns (basically) "foo"
    output1.text=grid.name();

    // This will give you the node attribute called name: 
    // <foo name="bar"/> returns bar
    output2.text=grid.@name;

    // This will give you the child node named 'name': 
    // <foo><name>Heidi</name></foo> returns <name>Heidi</name>, which, 
    // when translated, should output "Heidi" as text
    output3.text=grid.name;
}

If you use one of those judiciously, it will probably be closer to what you're looking for. 如果您明智地使用其中之一,它可能会更接近您要查找的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM