/ Published in: ActionScript 3
There has to be a better way to do this rather than using regular expressions to remove the various namespaces within the ATOM feed. Also variables could be reused (currently used for teaching so helpful to explain process). Based on:
http://www.republicofcode.com/tutorials/flash/as3xml/
http://stackoverflow.com/questions/673412/how-can-i-remove-a-namespace-from-an-xml-document
http://www.republicofcode.com/tutorials/flash/as3xml/
http://stackoverflow.com/questions/673412/how-can-i-remove-a-namespace-from-an-xml-document
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var query:String = "greenwich"; var myXML:XML; var myLoader:URLLoader = new URLLoader(); myLoader.load(new URLRequest("http://search.twitter.com/search.atom?lang=en&q="+query)); myLoader.addEventListener(Event.COMPLETE, processXML); function processXML(e:Event) { myXML = new XML(e.target.data); myXML = removeNS(myXML); // then use myXML object as normal to access various parts of the feed for (var i:int = 0; i < myXML.entry.length(); i++){ trace(myXML.entry.title[i]); } } function removeNS(anXML:XML){ var xmlString = anXML.toXMLString(); var xmlnsPattern = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi"); var namespaceRemovedXML = xmlString.replace(xmlnsPattern, ""); var aaaPattern = new RegExp("aaa:lang[^\"]*\"[^\"]*\"", "gi"); var aaaRemovedXML = namespaceRemovedXML.replace(aaaPattern, ""); var twitterPattern = new RegExp("twitter:", "gi"); var twitterRemovedXML = aaaRemovedXML.replace(twitterPattern,""); var openSearchPattern = new RegExp("openSearch:", "gi"); var openSearchRemovedXML = twitterRemovedXML.replace(openSearchPattern,""); var responseXML = new XML(openSearchRemovedXML); return responseXML; }