Return to Snippet

Revision: 39139
at January 13, 2011 23:35 by Activetuts


Initial Code
function stripXMLNamespaces(xml:XML):XML
{
    var s:String = xml.toString();
    var pattern1:RegExp = /\s*xmlns[^\'\"]*=[\'\"][^\'\"]*[\'\"]/gi;
    s = s.replace(pattern1, "");
    var pattern2:RegExp = /<[\/]{0,1}(\w+:).*?>/i;
    while(pattern2.test(s)) {
        s = s.replace(pattern2.exec(s)[1], "");
    }
    return XML(s);
}

Initial URL
http://enva.to/e4ig6z

Initial Description
<p>Loading XML, specifically from 3rd party sources can sometimes prove problematic when the XML makes use of namespaces. This snippet will take an XML object and strip all namespace declarations and prefixes. This snippet leaves the input XML unchanged and returns a new XML object.</p>

Initial Title
Strip XML Namespaces

Initial Tags

                                

Initial Language
ActionScript 3