[prev in list] [next in list] [prev in thread] [next in thread] 

List:       osflash-general
Subject:    [osflash] XMLSchema -> ActionScript
From:       stephan.bezoen () lostboys ! nl (Stephan Bezoen)
Date:       2006-10-25 4:49:44
Message-ID: 9D3B316D8519584C861AA273E47D6F9B20730E () mail01 ! lostboys ! nl
[Download RAW message or body]

Hi David,

I've been reading the whole conversation with particular interest since
I've been wondering about the same thing for a while now. Today at the
MAX conference I asked the developers of FLEX Builder if there was any
such thing in Flex, since it seems such a logical place for a tool like
this. The answer was that they have it on the list of possible features,
but haven't come that far. Would be nice if the cracks at Adobe could do
the hard work for us, in payed time, hehe.

Anyway, I've written a Parser class that takes data from XML converted
to AS-style Objects (so all is accessible in basic dot-notation) plus a
VO class name. The specified VO class implements an interface IParsable,
which has one function, parseObject (o:Object) : Boolean. Each VO class
takes care of its own parsing of the data into its member variables.
This construction saves the hassle of producing all the "unmarshallXXX"
functions in one single location: Each VO class can get its member
variables with types as defined in the XMLSchema, plus its parsing
functionality to go from the XML to the member variables.
I can send you source code if you like, it will be available in the
upcoming release of the ASAPFramework (www.asapframework.org).

Right now I'm most interested in a tool that will kindof "guess" (in an
educated way) the VO implementation from XML, rather than producing
schemas for all XML files. I don't mind having to do some handwork after
a tool has produced the basic code, as long as it saves me, say, 90% of
the boring work. I have the idea that especially the flexibility of the
XML standard can make a tool like this immensely complex very soon.

There should be tools like this out there for Java, and Actionscript
isn't that different from Java that it wouldn't be possible to adapt the
code. One condition will have to be that it's open source, obviously. If
I find the time, I'll have a look at Castor (www.castor.org), which
seems to do pretty much what we're looking at.

In the meantime, keep up the good work and keep us posted :)

Stephan


> -----Original Message-----
> From: osflash-bounces at osflash.org [mailto:osflash-bounces at osflash.org]
On
> Behalf Of David Holroyd
> Sent: dinsdag 26 september 2006 15:26
> To: osflash at osflash.org
> Subject: Re: [osflash] XMLSchema -> ActionScript
> 
> On Tue, Sep 26, 2006 at 07:49:21AM +0100, jtgxbass wrote:
> > Another interest is that one could use the same principal to
actually
> create
> > the XML parseing routine (a routine that takes the XML - which
conforms
> to
> > the schema -  and creates the VO instances at runtime). Akin to what
a
> SOAP
> > parser/implemetation does.
> 
> Indeed, the code I posted earlier takes a stab at doing that.  Here
are
> the results of running against the test Schema I've been using:
> 
> 
> ----8<----
> package com.example.merchandise._2005{
> 	public class Unmarshaler {
> 		public function
> unmarshalCatalogueCategory(thisElement:XML):CatalogueCategory {
> 			var _result:CatalogueCategory = new
CatalogueCategory();
> 			_result.id = thisElement. at id;
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.title = _children[_seq++].text();
> 			_result.description = _children[_seq++].text();
> 			_result.product = new Array();
> 			while (_seq<_children.length() &&
> _children[_seq].name()==new
QName("http://example.com/merchandise/2005",
> "product")) {
> 
> 	_result.product.push(unmarshalProduct(_children[_seq++]));
> 			}
> 			return _result;
> 		}
> 		public function unmarshalColour(thisElement:XML):Colour
> {
> 			var _result:Colour = new Colour();
> 			_result.id = thisElement. at id;
> 			_result.swatchhex = thisElement. at swatchhex;
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.description = _children[_seq++].text();
> 			_result.productshots =
> unmarshalProductShots(_children[_seq++]);
> 			return _result;
> 		}
> 		public function unmarshalImage(thisElement:XML):Image {
> 			var _result:Image = new Image();
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.imageSmall =
> unmarshalImageData(_children[_seq++]);
> 			_result.imageLarge =
> unmarshalImageData(_children[_seq++]);
> 			return _result;
> 		}
> 		public function
unmarshalImageData(thisElement:XML):ImageData
> {
> 			var _result:ImageData = new ImageData();
> 			_result.filename = thisElement. at filename;
> 			return _result;
> 		}
> 		public function
unmarshalProduct(thisElement:XML):Product {
> 			var _result:Product = new Product();
> 			_result.id = Number(thisElement. at id);
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.title = _children[_seq++].text();
> 			_result.description = _children[_seq++].text();
> 			_result.price =
Number(_children[_seq++].text());
> 			_result.colourvariations = new Array();
> 			for each(var _child:XML
in_children[_seq++].elements())
> {
> 
> 	_result.colourvariations.push(unmarshalColour(_child));
> 			}
> 			_result.sizevariations = new Array();
> 			for each(var _child:XML
in_children[_seq++].elements())
> {
> 
> 	_result.sizevariations.push(unmarshalSize(_child));
> 			}
> 			_result.skus = new Array();
> 			for each(var _child:XML
in_children[_seq++].elements())
> {
> 				_result.skus.push(unmarshalSKU(_child));
> 			}
> 			return _result;
> 		}
> 		public function
> unmarshalProductShots(thisElement:XML):ProductShots {
> 			var _result:ProductShots = new ProductShots();
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.image = new Array();
> 			while (_seq<_children.length() &&
> _children[_seq].name()==new
QName("http://example.com/merchandise/2005",
> "image")) {
> 
> 	_result.image.push(unmarshalImage(_children[_seq++]));
> 			}
> 			return _result;
> 		}
> 		public function unmarshalSize(thisElement:XML):Size {
> 			var _result:Size = new Size();
> 			_result.code = Number(thisElement. at code);
> 			var _children:XMLList = thisElement.children();
> 			var _seq:int = 0;
> 			_result.description = _children[_seq++].text();
> 			return _result;
> 		}
> 		public function unmarshalSKU(thisElement:XML):SKU {
> 			var _result:SKU = new SKU();
> 			_result.id = thisElement. at id;
> 			_result.colourId =
Number(thisElement. at colourId);
> 			_result.sizeId = Number(thisElement. at sizeId);
> 			return _result;
> 		}
> 	}
> }
> ---->8----
> 
> 
> ta,
> dave
> 
> --
> http://david.holroyd.me.uk/
> 
> _______________________________________________
> osflash mailing list
> osflash at osflash.org
> http://osflash.org/mailman/listinfo/osflash_osflash.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic