如何在运行时从 xsd 模式转到 Actionscript 对象 (Flex)? [英] How to go from xsd schema to Actionscript object (Flex) at runtime?

查看:20
本文介绍了如何在运行时从 xsd 模式转到 Actionscript 对象 (Flex)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里看到了 questions 这里询问 xsd->actionscript 对象,但这些似乎需要 xsd->java->actionscript 并且都在源代码中.我们的要求有点不同:

I have seen questions here asking about xsd->actionscript objects, but these seem to require xsd->java->actionscript and is all in source code. Our requirements are a bit different:

  1. 在运行时接收我们以前从未见过的 xsd
  2. 基于 xsd 创建一个实例对象
  3. 填写实例的值(来自 xml 文档或用户输入 - 随便)

有人知道可以帮助我们在运行时完成此操作的动作脚本库或工具吗?如果这样的东西已经存在就好了——但是我们肯定会满足于一个库,它为我们提供了一个编程接口来从 xsd 模式中提取信息.此外,我们会就替代方法提出建议以达到相同的目的.

Anyone know of an actionscript library or tool that would help us accomplish this at runtime? It would be nice if something like this already existed - but we would certainly settle for a library that gave us a programmatic interface to extract information from an xsd schema. Additionally, we would take suggestions on alternate methods to accomplish the same ends.

推荐答案

您是否看过 SchemaLaoder...?不完全是您要找的东西……但这是一个很好的开始.

Have you looked at the SchemaLaoder...? Not EXACTLY what you're looking for ... But a great start.

首先 - 您应该检查 this 博客条目和 这个 博客条目,它引导您完成Dominic De Lorenzo 拥有利用 Flex SDK 中的功能的经验,该功能提供自定义 ActionScript 类到 XML 架构 (XSD) 中元素定义的自动映射.

First - you should check this blog entry and this blog entry which walks you through Dominic De Lorenzo experiences with utilising functionality within the Flex SDK that provides the automatic mapping of custom ActionScript classes to element definitions within an XML Schema (XSD).

迁移到这里的步骤包括(来自 Dominic 的博客):

The steps to get moving here include (from Dominic's blog):

0) 创建 SchemaLoader 的实例并从给定的 URL 异步加载 XML 模式
1) 加载架构后,将其添加到 SchemaManager 并将任何 ActionScript 类注册到相应的架构类型

0) Create an instance of SchemaLoader and asynchronously load an XML schema from a given URL
1) Once the schema is loaded, add it to the SchemaManager and register any ActionScript classes to their corresponding schema type

----在这个阶段你可以根据schema做几个操作

---- At this stage you can do several operation based on the schema

2) 加载基于该架构的 XML 文件
3) 加载 XML 后,使用 XMLDecoder 对内容进行解码.解码xml时将使用在schemaTypeRegistry中注册的任何类
4) 使用 XMLEncoder 将自定义 ActionScript 类编码回 XML.XMLEncoder.encode() 支持在架构中定义相应元素(顶级元素、特定类型甚至自定义 XSD 定义)的各种方法,这些元素将用于对 Actionscript 对象进行编码.

2) Load an XML file based off that schema
3) Once the XML is loaded, decode the contents using XMLDecoder. Any classes registered in the schemaTypeRegistry will be used when decoding the xml
4) Encode a custom ActionScript class back into XML using XMLEncoder. XMLEncoder.encode() supports various ways to define the corresponding element in the schema (top level element, a specific type or even a custom XSD definition) that will be used to encode the Actionscript object.

该博客条目包含代码示例等链接...

The blog entry has links to code samples, etc...

希望这会有所帮助.

这篇关于如何在运行时从 xsd 模式转到 Actionscript 对象 (Flex)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆