javascript 从 xsd 获取 html 表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8274615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get html form from xsd
提问by Tommaso
I have a quite complex xsd file that describe some objects (it's not important, but it's the DATEX II standard) Do you know if there is an automatic way to create an html form that act like a "wizard" to guide the user to create xml object as described in the xsd?
我有一个相当复杂的 xsd 文件,它描述了一些对象(这并不重要,但它是 DATEX II 标准)你知道是否有一种自动方法来创建一个 html 表单,它就像一个“向导”来引导用户创建xml 对象如 xsd 中所述?
回答by Petru Gardea
The answer to this depends on the intended user base, how you want your users to access your forms, and the technology stack you have in place already or you're willing to deploy.
答案取决于预期的用户群、您希望用户如何访问您的表单以及您已经拥有或愿意部署的技术堆栈。
If your users are quality control analysts, and so the intent is to have them use that generated UI to manage test cases, then a handful of commercial tools have this ability. A quick search on Google for terms such as "generate ui forms from XSD to test web services" should give you on first page the major players in this space (I won't name names to avoid conflict of interests). There are differences in how vendors approach this, that have to do with the time it takes to generate these forms from large bodies of XML Schema, which in turn translate into different degrees of usability. Given what I see in DATEX, from a complexity perspective, you may have a hard time to find a free tool for this...
如果您的用户是质量控制分析师,因此目的是让他们使用生成的 UI 来管理测试用例,那么少数商业工具具有这种能力。在 Google 上快速搜索诸如“从 XSD 生成 ui 表单以测试 Web 服务”之类的术语应该会在第一页为您提供该领域的主要参与者(为了避免利益冲突,我不会点名)。供应商对此的处理方式存在差异,这与从大型 XML Schema 主体生成这些表单所需的时间有关,这反过来又转化为不同程度的可用性。鉴于我在 DATEX 中看到的情况,从复杂性的角度来看,您可能很难找到一个免费的工具来解决这个问题……
If your users are rather data entry specialists, then the above are not the tools you want them to use. Without knowing much about your environment (I see your java-ee tag, but still not clear how it would relate to this task), one model could be a combination of InfoPath with SharePoint; while the process to generate the form is not fully automatic, it comes close to that. It is XSD driven, in the sense that at design time you drag and drop XSD on a design form, that allows you to build some really nice UI. Follow their competition on your particular technology stack and you may have your answer. Or, you can go to this sitethat lists XForms implementations; IBM's form designer, much like InfoPath, can use XML Schema for design, etc.
如果您的用户是数据输入专家,那么上述工具就不是您希望他们使用的工具。在不太了解您的环境的情况下(我看到了您的 java-ee 标签,但仍不清楚它与此任务的关系),一个模型可能是 InfoPath 与 SharePoint 的组合;虽然生成表单的过程不是完全自动的,但它接近于此。它是 XSD 驱动的,从某种意义上说,在设计时您将 XSD 拖放到设计表单上,这允许您构建一些非常好的 UI。关注他们在您的特定技术堆栈上的竞争,您可能会有答案。或者,您可以访问这个列出 XForms 实现的站点;IBM 的表单设计器,很像 InfoPath,可以使用 XML Schema 进行设计等。
If this is for developers to get some XML, another alternative might also be to go with an Excel based (or SharePoint lists) approach and generate XML from that data (you give away cost to acquire something to build specific to your requirements tooling, here assuming people that are really familiar with spreadsheets instead).
如果这是让开发人员获得一些 XML,另一种选择也可能是使用基于 Excel(或 SharePoint 列表)的方法并从该数据生成 XML(您放弃获取某些东西以构建特定于您的需求工具的成本,这里假设人们真正熟悉电子表格)。
Given how DATEX model looks like, you'll have to do some manual customizations anyway, if you plan to use the extensibility model, or if you choose to build different forms for different scenarios i.e. instead of one big form that'll give you all descendents for the abstract payloadPublication in some drop down, to just a specific, simple form e.g. MeasurementSiteTablePublication.
鉴于 DATEX 模型的外观,如果您打算使用可扩展性模型,或者如果您选择为不同的场景构建不同的表单,即,而不是为您提供所有内容的一个大表单,您无论如何都必须进行一些手动定制某些下拉列表中抽象payloadPublication 的后代,只是一个特定的简单形式,例如MeasurementSiteTablePublication。
回答by Michiel Meulendijk
I know this is an old question, but I ran into this issue myself and couldn't find a satisfying open-source solution. I ended up writing my own implementation, XSD2HTML2XML. To my knowledge it is the most complete tool out there. It supports automatic generation of HTML forms from XSD, including the population of a form with XML data.
我知道这是一个老问题,但我自己遇到了这个问题,找不到令人满意的开源解决方案。我最终编写了自己的实现XSD2HTML2XML。据我所知,它是最完整的工具。它支持从 XSD 自动生成 HTML 表单,包括使用 XML 数据填充表单。
If you prefer an out-of-the-box solution rather than writing your own, please see my implementation, XML Schema Form Generator.
如果您更喜欢开箱即用的解决方案而不是编写自己的解决方案,请参阅我的实现XML Schema Form Generator。