本文档目前正在完善中...asSchema是一个AIR应用程序,它可以将XML Schema文档自动转为Action Script 3代码。 asSchema is a XML Schema files automatically become the three Action Script 3 code RIA application. 关于asSchema Introduction asSchema在多数情况下,Action Script 3读取XML文档节点内容必须采用XML对象和XMLList对象来完成,除非您有编写其他的解析程序(如:XMLTabel、AStoObject)。否则,您不得不在编写代码时,常常要打开对应的XML文档来确定要读取的内容和位置,因而,由于粗心和对XML结构的不熟悉常常会导致一些潜在的程序缺陷。 In most cases, Action Script 3 to read XML nodes to be used as objects and XML XMLLis t object to accomplish, unless you are prepared other analytical procedures (such as : XMLTabel. AStoObject). Otherwise, you have to prepare yourself, are often open to the corresponding XML document to be read to determine the content and location, Thus, due to careless and XML are not familiar with the structure often leads to a number of potential shortcomings of the process. 如果项目需求发生变化,不得不修改之前所定义的XML文档,那么,随之带来的是您必须查找代码中解析XML的地方,对其进行逐一的更改。 If the project needs change, which must be revised before the definition of XML documents, then attendant is that you must find the code parsing XML where each of its changes. 使用asSchema,可以将原来需要手动编写解析XML的代码生成出来,在项目中通过实例化一个对象,来获取XML文档中所有的节点值,而这些,都是自动完成的。如果XML定义有改变,您只需要重新生成一次,并替换原有代码,我相信,您的开发工具会通过错误信息告诉您所有的变动——您只要一一修改就可以完成所有的变更。 asSchema use, the original will need to be prepared manually parsing XML code generation, and in the project through examples of an object, XML documents to obtain all the nodes value, which, all done automatically. If the XML definition of a change, you only need to rebuild the once, and the replacement of the original code, I believe, your development tools through the wrong message will tell you all the changes -- as long as you can change on January 1 to complete all the changes. 安装asSchema installation asSchema- asSchema是一个AIR应用程序,因此,必须先安装AIR运行环境。如果您还没有AIR运行环境,请到Adobe下载。
。The first thing you're going to need is the Adobe Integrated Runtime (AIR) which you can get from Adobe. - 然后,请到以下地址下载最新的版本:
Then, please address the following download the latest version :
使用asSchema生成代码 Generating source code from asSchema下面将介绍如何通过asSchema生成需要的代码: Below will introduce how asSchema code generation needs: - 打开Wersling asSchema应用程序:Wersling asSchema open Application Program
- 选择将要生成代码的XML Schema文档:Selection will be generated code XML Schema Documentation
- 选择代码生成目录的位置:Code Generation choose the location of Contents
- 在Package栏输入生成代码的包路径(不是必须的),设置包路径,将在代码的Package中体现。例如:输入“com.samples”,则生成的代码第一行为:Fill in Package packages generated code path (not a must), set up packet path The code will be reflected Package. For example : Admission "com.samples", the first generation of code behavior:
package com.samples - 在Author栏输入您或公司的名称(不是必须的),设置Author将在代码的类注释中体现。例如:输入“my Name”,则生成代码的类文档为:Author Fill in your name or company (not a must), Author will be set up in the Notes category code embodied. For example : the importation of "my Name", the generated code for the category of documents
/**
* A Application Node
* @author my Name
*
*/ - 选择模板文件(不是必须的),模板文件是一个XML文档,它必须符合软件中apl.xsd文档的约束。您可以根据apl.xsd文档格式来建立自己的模板,一般情况使用默认的模板就可以。Choose a template document (not a must), the template file is an XML document, It must meet the software apl.xsd document constraints. You can apl.xsd file format to create their own templates and generally use the default template can be.
- “Generation Annotion”单选项确定是(选择)否(不选择)生成注释。"Generation Annotion" single set of options (choice) No (not by choice) Generation Notes.
- “Strong Funtion”单选择确定是(选择)否(不选择)生成更多读取XML方法的函数,如:getNodeMinCount(),getNodeMaxCount(),hasNode()等。"Strong Funtion" single-choice was confirmed (by choice) not (not by choice) to read more Generation X ML method of function, such as : getNodeMinCount (), getNodeMaxCount (), hasNode ().
- 所有的设置类似下图:All set up under a similar plan :
- 点击”Start!”按钮开始生成代码。或点击”Reset”重新设置之前的参数。Click on the "Start!" Button to begin generating code. Or click on "Reset" to re-set the parameters before.
- 查看程序下方的信息,只到看到“Build Files Complete!”则代表执行完成。View the bottom of the information process, only to see that the "Build Files Complete!" on behalf of the implementation of the completion.
- 完成转换,查看并使用生成的代码!Complete conversion to detect and use the code generation!
使用生成的代码 Usage of generated code下面内容演示采用Flex开发工具使用asSchema生成的代码: Now used as demonstration of the use of Flex development tools generate code asSchema: 下载示例文件 : Download sample file : - 运行Flex;Operation Flex;
- 新建一个”ActionScript Project”;Create a "ActionScript Project";
- 将生成的代码拷贝到项目的代码目录;Will generate the code to copy the code directory;
- 在Flex中打开”Test.as”文件并修改,以” Languages.xsd”生成的代码为例,修改”Test.as”为以下形式:Flex opened in "Test.as" document and modify, "Languages.xsd" generated code as an example. changes "Test.as" for the following forms:
package
{
import com.samples.ApplicationInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class Test extends Sprite
{
/*
TODO
Insert your code here...
Example code to create and load a XML File:
*/
public function Test(){
var xmlloader:URLLoader = new URLLoader();
xmlloader.addEventListener(Event.COMPLETE,loaded);
xmlloader.load(new URLRequest("English.xml"));
}
private function loaded(e:Event):void{
var xml:XML = XML(e.target.data);
var doc:ApplicationInfo = new ApplicationInfo(xml);
trace(doc);
}
}
}- 拷贝安装目录下”samples\English.xml”文件到”bin”目录;Copy the installation directory under "samples \ English.xml" document to the "bin" directory;
- 测试这个项目,查看”Console”的输出内容.The project tests to detect the "Console" output .
下面的代码演示如何使用asSchema生成的对象: The following code shows how to use the object asSchema Generation : 下载示例文件 : Download sample file : package {
import com.samples.LevelInfo;
import com.samples.MessageWinInfo;
import com.samples.OpenInfo;
import flash.display.Sprite;
/**
* This example shows how to use asSchema generated code.
*
* Contact:wersling@gmail.com
* @author wersling
*
*/
public class asSchemaTest extends Sprite
{
public function asSchemaTest()
{
testSimpleType();
testComplexType();
testElement();
}
public function testSimpleType():void{
var xml:XML = new XML("<Level>INFO</Level>");
var info:LevelInfo = new LevelInfo(xml);
trace(info); //INFO
trace(info.index == LevelInfo.EINFO); //true
}
public function testComplexType():void{
var xml:XML = new XML("<MessageWin><Level>INFO</Level><Message>a Message</Message></MessageWin>");
var info:MessageWinInfo = new MessageWinInfo(xml);
trace(info.getLevel()); //INFO
trace(info.getMessage()); //a Message
trace(info.getLevelCount()); //1
trace(info.getMessageCount()); //1
}
public function testElement():void{
var xml:XML = new XML("<Open Index='0' ShortcutKey='O'>Open...</Open>");
var info:OpenInfo = new OpenInfo(xml);
trace(info.getIndex()); //0
trace(info.getShortcutKey()); //0
trace(info.getValue()) //Open...
}
}
}asSchema 支持 asSchema support以下内容列出asSchema所支持Schema元素 The following list asSchema support elements Schema - XML Namespaces
- 支持类型:Support types
- 内在的XML Schema 类型:所有类型都继承asSchema类型包。Built-in XML Schema types: Mapped to classes in the asSchema types library.
- 支持扩展。Derived by extension.
- 支持约束。Derived by restriction.
- 复合类型。 Complex types.
- 简单类型。 Simple types.
- 复合内容。Complex content.
- 简单内容。Simple content.
- 枚举。Enumerations.
- 模式。Patterns.
- 内置Node节点。Built-in anyType node.
- 自定义复合类型。User-defined complex types.
- 元素组和属性组。Groups and AttributeGroup.
- 任意元素和任意类型。Any and any AnyAttribute.
- 注释。Annotation.
- 下列各项,目前不支持或不能完整的支持。The following advanced XML Schema features are not, or not fully supported:
- 内容模式(sequence, choice, all),可以解析,但不支持对应的约束。Content models (sequence, choice, all).Analysis can, but do not support the corresponding constraint.
- 唯一性约束。Uniqueness constraints.
- 关键字。Key and keyref.
- 重复的命名。此项包括对任何类型和内容。Duplicate names. This right includes any type and content.
//以下定义中包含一个重复的复合类型节点:"Menu",这将导致无法正确执行:
<xs:element name="Root">
<xs:complexType id="Menu">
<xs:sequence>
<xs:element name="Menu">
<xs:complexType>
<xs:sequence>
<xs:element name="File"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Menu"/>
//此时,你必须将其中一个修改,象这样:
<xs:element name="Root">
<xs:complexType id="Menu">
<xs:sequence>
<xs:element name="Menu">
<xs:complexType>
<xs:sequence>
<xs:element name="File"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="MenuItem"/> - ActionScript3关键字。ActionScript3 Key.
//以下定义包含关键字,将导致与内置对象冲突。
<xs:complexType name="if"/>
<xs:complexType name="Array"/>
<xs:complexType name="Date"/>
内置类型Built in Types这个章节描述asSchema生成代码中的内置类型. This chapter describes asSchema generation of embedded code types. | 属性 Property | 描述 Description | | Node | 解析XML节点中的元素和属性值 Parsing XML node elements and attribute values | | SchemaBoolean | 布尔类型节点对象 Boolean type of object nodes | | SchemaByte | 字节类型节点对象 Byte type of object nodes | | SchemaInt | 整数类型节点对象 Int type of object nodes | | SchemaNumber | 浮点类型节点对象 Number type of object nodes | | SchemaString | 字符串类型节点对象 String type of object nodes | | SchemaUint | 怎整数类型节点对象 Uint type of object nodes |
注意:任何生成的代码都继承Node类,不存在的类型默认为SchemaString类型 Note : any code generated succession Node category, not the type of default type for SchemaString_
|