massiveinteractive/mloader — pull request #2 by misprintt (2012-08-29 01:57:55+00:00)
Title: added optional parseData callback to JsonLoader and XmlLoader

This enables validation/extraction of typed content data from the raw payload prior to triggering loaderComplete (without having to extend JsonLoader or XmlLoader

A primary usecase is an XML or JSON request where the response object is wrapped in a server result object containing session/status/error codes and the actual data payload (e.g. an XML SOAP wrapper)

### Basic JsonLoader Usage

function execute()
{
var loader:JsonLoader = new JsonLoader("http://localhost/data.json");
loader.parseData = customDataParser;
loader.load();
}

function customDataParser(data:Dynamic):Foo
{
if(data.Status == 0)
{
return data.foo;
}
else
throw "Server error " + data.errorCode;
return null;
}
}

### Basic XmlLoader Usage

function execute()
{
var loader:XmlLoader = new XmlLoader("http://localhost/data.xml");
loader.parseData = customDataParser;
loader.load();
}

function customDataParser(xml:Xml):Xml
{
for(element in xml.elements())
{
if(element.nodeName == "errorCode")
{
throw "XML Error " + element.nodeValue;
}
else if(element.nodeName == "payload")
{
return element;
}
}

throw "Missing XML payload";
return null;
}

### Also

- updated class docs for JSON and XMLLoader
- added test/LoaderAssert to assert on enum parameter equality