I have written reading catalog.xml program in ActionScript 3.0.
I know my code is not perfect however I make my code public because I would like to help someone who would like to analyze catalog.xml... hope it helps :)
In short the code is simply reading xml file.
SWCCatalog and SWCVersions class are simply data class, which hold extracted data from catalog.xml.
I know my code is not perfect however I make my code public because I would like to help someone who would like to analyze catalog.xml... hope it helps :)
In short the code is simply reading xml file.
package utils.tool { public class CatalogXmlReader { // you should change the namespace based on flash version private static const NS:String = "http://www.adobe.com/flash/swccatalog/9"; public function CatalogXmlReader() { } public function create(xml:XML):SWCCatalog { var ns:Namespace = getDefaultNamespace(xml); if (!(ns.uri === NS)) throw new Error("Namespace is wrong"); var versions:XMLList = xml.child(new QName(ns, "versions")); var swcVersion:SWCVersions = new SWCVersions(); swcVersion.swcVersion = versions.child(new QName(ns, "swc")).@version; swcVersion.flexVersion = versions.child(new QName(ns, "flex")).@version; var swcCatalog:SWCCatalog = new SWCCatalog(); swcCatalog.versions = swcVersion; for each(var clazz:String in xml.child(new QName(ns, "libraries")).child(new QName(ns, "library")).child(new QName(ns, "script")).child(new QName(ns, "def")).attribute("id")){ swcCatalog.classes.push(clazz.replace(":",".")); } return swcCatalog; } protected static function getDefaultNamespace(xml:XML):Namespace { for each(var elem:Namespace in xml.namespaceDeclarations()) { if (elem.prefix == "") { return new Namespace("", NS); } } return new Namespace(); } } }
SWCCatalog and SWCVersions class are simply data class, which hold extracted data from catalog.xml.
package utils.tool { public class SWCCatalog { private var _versions:SWCVersions; private var _classes:Vector.<String> = new Vector.<String>(); public function SWCCatalog() { } public function get versions():SWCVersions { return _versions; } public function set versions(value:SWCVersions):void { _versions = value; } public function get classes():Vector.<String> { return _classes; } } }
package utils.tool { public class SWCVersions { private var _swcVersion:String; private var _flexVersion:String; public function SWCVersions() { } public function get swcVersion():String { return _swcVersion; } public function set swcVersion(value:String):void { _swcVersion = value; } public function get flexVersion():String { return _flexVersion; } public function set flexVersion(value:String):void { _flexVersion = value; } } }
コメント