Created
September 18, 2010 08:22
Revisions
-
bitfade renamed this gist
Sep 22, 2010 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bitfade renamed this gist
Sep 22, 2010 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bitfade revised this gist
Sep 18, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /* Author: bitfade this class will convert a XML configuration in to a simpler object */ package bitfade.utils { -
bitfade created this gist
Sep 18, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ /* this class will convert a XML configuration in to a simpler object */ package bitfade.utils { import flash.xml.* public class XmlParser { public static function toObject(xml:XML):Object { var obj:Object = {} var el:XML var name:String var value:Object // for each attribute for each(el in xml.@*) { name = el.localName() obj[name] = String(xml.attribute(name)); } // if have text, add it value = xml.text().toString() if (value) obj.content = value // for each element if (xml.hasComplexContent()) { for each(el in xml.*) { name = el.localName() value = XmlParser.toObject(el) if (obj[name] is Array) { obj[name].push(value) } else { obj[name] = [value] } } } return obj } // strips namespaces for simpler parsing public static function clean(input:XML):XML { var purified:String = input.toString() purified = purified.replace(/<(\/)?(\w+:)(\w+)/g, "<$1$3"); purified = purified.replace(/\w+:(\w+)=\"/g, "$1=\""); purified = purified.replace(/xmlns(:\w+)?=\"([^\"]+)\"/g, ""); return new XML(purified) } } }