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 = [EMAIL PROTECTED];
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 = [EMAIL PROTECTED];
_result.swatchhex = [EMAIL PROTECTED];
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 = [EMAIL PROTECTED];
return _result;
}
public function unmarshalProduct(thisElement:XML):Product {
var _result:Product = new Product();
_result.id = Number([EMAIL PROTECTED]);
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([EMAIL PROTECTED]);
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 = [EMAIL PROTECTED];
_result.colourId = Number([EMAIL PROTECTED]);
_result.sizeId = Number([EMAIL PROTECTED]);
return _result;
}
}
}
---->8----
ta,
dave
--
http://david.holroyd.me.uk/
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org