November 30, 2009

ActionScript and XML

I have been playing around with Flex/ActionScript for quite some time now and as an experienced Java developer I must say I like it a lot. I will share some findings in this space (mostly because my memory is not what it should be so it's a good place for me to re-find my findings :-)).

Howto-Marshal:
protected function marshalMetaMedia(order:Order) : XML {
var xml:XML =
<ns:order xmlns:ns="http://www.ordersystem.se/schema/order/1.0">
<id>{order.id}</id>
</ns:metamedia>;
return xml;
}
See how simple it is to create XML and to intertwine it with the values passed to the method! It's to easy to believe, huh? :-)

HowTo-Unmarshal:
protected function unmarshalOrder(xml:XML):MetaMedia {
var order:Order = new Order();
order.id = xml["id"].text();
return order;
}

Simple is beautiful!

0 comments: