Strip XML Namespaces


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. function stripXMLNamespaces(xml:XML):XML
  2. {
  3. var s:String = xml.toString();
  4. var pattern1:RegExp = /\s*xmlns[^\'\"]*=[\'\"][^\'\"]*[\'\"]/gi;
  5. s = s.replace(pattern1, "");
  6. var pattern2:RegExp = /&lt;[\/]{0,1}(\w+:).*?&gt;/i;
  7. while(pattern2.test(s)) {
  8. s = s.replace(pattern2.exec(s)[1], "");
  9. }
  10. return XML(s);
  11. }

URL: http://enva.to/e4ig6z

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.