Coder Social home page Coder Social logo

xml-2-typed-object's Introduction

xml-2-typed-object

XML2VO.as is an as3 utility to parse xml into typed as3 objects

The following is an example of how to use the XML2VO.as util to quickly map data from xml into a typed object.

private var loader:URLLoader;
private var exampleVO:ExampleVO;

private function init():void 
{
	exampleVO = new ExampleVO();
	var url:String = "config.xml";
	loader = new URLLoader();
	var request:URLRequest = new URLRequest(url);
	loader.addEventListener(Event.COMPLETE, OnLoadComplete);
	loader.load(request);
}

First you'll need to load or embed your xml object.

private function OnLoadComplete(e:Event):void 
{
	XML2VO.map(XML(loader.data), exampleVO);
}

Then on load complete simply call XML2VO.map and pass in the xml data along with the object you'd like the data mapped to.
example source xml is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<data>
	<arrayExample>1, 3.2, test</arrayExample>
	<intExample>60</intExample>
	<numberExample>30.45</numberExample>
	<stringExample>http://google.com</stringExample>
	<uintExample>0xded6ce</uintExample>
	<vectorExample>0xded6ce, 0xd1d6e0, 0xcddce2</vectorExample>
	<xmlExample>
		<item id="123">
			<img>test.jpg</img>
		</item>
	</xmlExample>
</data>

and ExampleVO is as follows:

package  
{
	public class ExampleVO 
	{
		public var arrayExample:Array;
		public var intExample:int;
		public var numberExample:Number;
		public var stringExample:String;
		public var uintExample:uint;
		public var vectorExample:Vector.;
		public var xmlExample:XML;
	}
}

private function OnLoadComplete(e:Event):void 
{
	XML2VO.map(XML(loader.data), exampleVO);
	MonsterDebugger.initialize(exampleVO);
}
By using MonsterDebugger to display the content of exampleVO you can see that the xml data has successfully been mapped into our as3 object. monsterDebugger

xml-2-typed-object's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.