简体   繁体   中英

Actionscript 3.0 - Is there a way to store XML namespaces in an array?

Hello i'd like to know if it's possible to store namespaces in an array? Imagine i had infinite namespaces and i'd use "for" to store them automatically, what would i need? i don't think an array would save namespaces as they are.

Just get your XML file into XML object and call namespaceDeclarations() :

var xml:XML =
    <root xmlns:ns="some.namespace">
        <ns:element/>
    </root>;
var namespaces:Array = xml.namespaceDeclarations();

Here namespaces is Array of Namespace objects. First one has prefix "ns" and uri "some.namespace".

Like Alexx said,

var xml:XML =
    <root xmlns:ns="some.namespace">
        <ns:element/>
    </root>;
var namespaces:Array = xml.namespaceDeclarations();

Arrays in ActionScript are not fixed-size (like in C++). This means that you can add / remove from the array VERY easily. To add an item into the array, use myArray.push(myItem);

To remove is a bit more complicated.

To remove the last item, use myArray.pop();

Suppose you have an array

var a:Array=[1, 2, 3, 4, 5, 6];
a.splice(3, 1); //Result: [1, 2, 3, 5, 6] Removes 1 element from array index 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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