Is there a way to copy an XMLList and keep the namespace? It seems when I use the copy() method on an XMLList the namespace is being removed.
Code:
var xml:XML = <s:Label xmlns:s="library://ns.adobe.com/flex/spark"><s:color>red</s:color>
test level</s:Label>;
var elementsXMLList:XMLList = xml.elements();
trace(elementsXMLList.toXMLString()); // has namespaces
var elementsCopy:XMLList = elementsXMLList.copy();
trace(elementsCopy.toXMLString()); // does not have namespaces
elementsXMLList.toXMLString():
<s:color xmlns:s="library://ns.adobe.com/flex/spark">red</s:color>
elementsCopy().toXMLString():
<color xmlns="library://ns.adobe.com/flex/spark">red</color>
I need to be able to keep the namespace when I make the copy.
This must be because it is
s:Labelnode that contains the namespace declaration.xml.elements()gets you a list of xml elements that are part ofs:Label's tree, so they do know their namespace. When you doelements.copy()though you get a separate list of XML elements that are no longer part of the tree that hasxmlns:s.I'd suggest that you copy the whole tree starting with
s:Label, then get its elements, instead of doing it another way around.