Wedia XMLSerializer Beta 1.0
Wedia XMLSerializer is developed by me and is used as a tool for serialize an object to xml and deserialize xml to an object, and aslo provide some ways for you to get all the public informations about the class, such as public variables, getters, setters, methods and constructor infomations, and aslo provide some utilities for string and date formate. With the collections in wedia.collections package you can write your collections extends from List or Directory that have strong types. Everyone can rewrite it for your own need. If you’re interesting in making friends me, that would be my pleasure.. You can see a demo below.
package
{
public class Person
{
[XMLAttribute()]
public var name:String;
[XMLAttribute()]
public var sex:String;
[XMLAttribute(ignore="true")]
public var age:int;
public var birthday:Date;
}
}
package
{
public class Parent extends Person
{
[ArrayAttribute(elemType="Person", name="child", add="add")]
public var children:Array;
}
}
package
{
import flash.display.Sprite;
import wedia.reflection.Type;
import wedia.serialization.XMLSerializer;
public class WediaXMLSerializerExample extends Sprite
{
public function WediaXMLSerializerExample()
{
this.serialize();
this.deserialze();
}
private function serialize():void
{
var parent:Parent = new Parent();
parent.age = 22;
parent.name = "Bing";
parent.birthday = new Date(1987, 2, 15);
parent.sex = "man";
var child1:Person = new Person();
child1.age = 1;
child1.name = "child1";
child1.sex = "girl";
child1.birthday = new Date(2008, 5, 26);
var child2:Person = new Person();
child2.age = 1;
child2.name = "child2";
child2.sex = "girl";
child2.birthday = new Date(2008, 7, 23);
parent.children = new Array();
parent.children.push(child1);
parent.children.push(child2);
trace(XMLSerializer.serialize(parent));
//output:
// <Parent name="Bing" sex="man">
// <children>
// <child name="child1" sex="girl">
// <birthday>Thu Jun 26 00:00:00 GMT+0800 2008</birthday>
// </child>
// <child name="child2" sex="girl">
// <birthday>Sat Aug 23 00:00:00 GMT+0800 2008</birthday>
// </child>
// </children>
// <birthday>Sun Mar 15 00:00:00 GMT+0800 1987</birthday>
// </Parent>
}
private function deserialze():void
{
var parent:Parent = new Parent();
var xml:XML = <Parent name="Bing" sex="man">
<children>
<child name="child1" sex="girl">
<birthday>Thu Jun 26 00:00:00 GMT+0800 2008</birthday>
</child>
<child name="child2" sex="girl">
<birthday>Sat Aug 23 00:00:00 GMT+0800 2008</birthday>
</child>
</children>
<birthday>Sun Mar 15 00:00:00 GMT+0800 1987</birthday>
</Parent>
parent = Parent(XMLSerializer.deserialize(Type.typeOf(parent), xml));
trace(parent.birthday); // output: Sun Mar 15 00:00:00 GMT+0800 1987
trace(parent.name);// output: Bing
trace(parent.sex);// output: man
trace(parent.age);// output:0, because it was igonred
trace(parent.children.length); // output: 2
}
}
}
Wedia XMLSerializer is a tool for uses to serialize and deserialze for object or xml, and aslo provide some methods to get the class’s public informations such as variables, getters, setters, methods and instructor informations. In this small framework, It aslo provide some utilities for string format. Now it’s just in Beta version, many features are not allowed in this version. Its main features are listed below:
-
XML Serialzier Support
- Support public variables
- Support XMLArribute tag for variable
- Support ignore attribute, the default value is false, which means the XMLSerializer will parse this varialbes
- Support ArrayArribute tag for variable or class
- Support elemType attribute which is used for deep serialization. This arrtibute should be always be set
- Support name attribute which is used for the node name of the array element
- Support add attribute which is used for insert element when deserialize. You should set this attribute whenever you want to write your own list
- Public information Support
- Get all public variables informations
- Get all public getters and setters informations
- Get all public methods informations
- Get constructor informations
- Get class informations, such as isStatic, isFinal and base
- Utitlies
- StringFormat, support Date Format
- Date utitiles
- Collections
- Strong types for List
- Strong types for dictionary. Note: Dictionary is not supported in Wedia XMLSerialzier
You can see the Wedia XMLSerializer API documents here.
Code Project: http://code.google.com/p/as3-wedia-xmlserialization/