Search code examples
apache-flexxml-namespacese4x

Dealing with namespaces in E4X


I'm trying to get data from a namespaced xml file in a flex app. There is a root namespace (xmlns="blah") and another namespace (xmlns:i="blah"), and I'm able to access most tags using the following:

var ns:Namespace = doc.namespace();
var result:XMLList = doc.ns::element;

However, there are several tags that are subject to change in the application, and i'd like to not hardcode them, possibly using the elements method:

var result:XMLList = doc.elements(configuredField);

Is there a way to get elements with namespaces using the elements method, or a similar way to get XML elements in flex using a parameter?


Solution

  • If I understand you, you can get nodes by using dynamic properties ([ ] notation).

    var x:XML=
    <root xmlns:i="testNS">
        <elem1>
            hhh
        </elem1>
        <i:elem2>
            123123
        </i:elem2>
    </root>;
    var elemName:String="elem2";
    var ns:Namespace=x.namespace("i");
    var tags:*=x.ns::[elemName]; //will contain all "elem2" tags in "i" namespace