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.
-
3It'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? :)alxx– alxx2011-11-29 04:51:05 +00:00Commented 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.bunnyannihilator89– bunnyannihilator892011-11-30 03:49:58 +00:00Commented 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.bunnyannihilator89– bunnyannihilator892011-11-30 04:00:01 +00:00Commented Nov 30, 2011 at 4:00
-
Ahh, XML namespaces! With no single mention of XML, I could think only of AS3.0 namespaces.alxx– alxx2011-11-30 04:52:49 +00:00Commented Nov 30, 2011 at 4:52
Add a comment
|
2 Answers
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".
1 Comment
bunnyannihilator89
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 :)
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