Generating ActionScript value objects from an xsd schema

妖精的绣舞 提交于 2019-12-11 01:15:33

问题


Are there any tools available for transforming types defined in an xsd schema (may or may not include other xsd files) into ActionScript value objects? I've been googling this for a while but can't seem to find any tools and I'm pondering wether writing such a tool would save us more time right now than to simply code our value objects by hand.

Another possibility I've been considering is using a tool such as XMLBeans to transform the types defined by the schema to Java classes and then converting those classes in ActionScript. However, I've come to realize that there are about a gazillion java -> as3 converters out there and the general consesus seems to be that they sort of work, ie, I have no idea which tool is a good fit.

Any thoughts?


回答1:


For Java -> AS generation, check out GAS3 from the Granite Data Services project:

http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator

This is the kind of thing you can write yourself too, especially if you leverage a tool like Ant and write a custom Task to handle it. In fact, I worked on this last year and open-sourced it:

https://github.com/cliffmeyers/Java2As




回答2:


I don't have any kind of translator either. What I do is have an XML object wrapped by an ActionScript object. Then you have a getter/setter for each value that converts xml->whatever and whatever->XML. You still have to write the getter/setter though, but you can have a macro/snippit handle that work for you.

So for XML like:

<person>
    <name>Bob</name>
    ...
</person>

Then we have an XML Object Wrapper class and extend it. Normally

class XMLObjectWrapper
{
    var _XMLObject:XML;

    function set XMLObject(xml:XML):void
    {
        _XMLObject = xml;
    }

    function get XMLObject():XML
    {
        return _XMLObject;
    }
}

class person extends XMLObjectWrapper
{
    function set name(value:String):void
    {
        _XMLObject.name = value;
    }

    function get name():String
    {
        return _XMLObject.name;
    }

}


来源:https://stackoverflow.com/questions/635594/generating-actionscript-value-objects-from-an-xsd-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!