0

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.

4
  • 3
    It's odd to see someone needs to process namespaces in runtime. What do you do with them? Are you sure you know what namespace is? :) Commented Nov 29, 2011 at 4:51
  • i need them to read namespaces in a xml file. my intention is to make a class and the user would set in the namespace and its url. that'd be saved in an array and then used like a string which would be then passed as arguments to generate all the namespaces needed with one line inside a loop(ex: for). Then i'd need to call each of the namespace generated (a specific one) to get to the xml file and get the data i want. Commented Nov 30, 2011 at 3:49
  • basecally i'm trying to make a class which opens any xml with namespaces, so that question i made you is like a prototype or investigation for further steps :) because i know that to do it i'd need to tell my class to read the header of the xml file and generate namespace to store them and their urls. Commented Nov 30, 2011 at 4:00
  • Ahh, XML namespaces! With no single mention of XML, I could think only of AS3.0 namespaces. Commented Nov 30, 2011 at 4:52

2 Answers 2

1

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".

Sign up to request clarification or add additional context in comments.

1 Comment

so basically you're saying if i use namespaceDeclarations() in my xml object it'll automatically understand and catch all the namespaces declared in my xml file? is it that easy? Thank you for the feedback. I'll be saying something when i try it :)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.