C# 自动从 XML 模式创建 GUI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/983399/
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
Create a GUI from a XML schema automatically
提问by
I have to write a desktop application to edit data stored in a XML file. The format is defined by a XML schema file (.xsd). The format is quite complex.
我必须编写一个桌面应用程序来编辑存储在 XML 文件中的数据。该格式由 XML 架构文件 (.xsd) 定义。格式相当复杂。
Are there tools which can generate a basic GUI automatically? It's not yet decided which language to use. I have experience in Python and C++ using wxWidgets and C# (.NET 1) using Windows Forms.
是否有可以自动生成基本 GUI 的工具?尚未决定使用哪种语言。我有使用 wxWidgets 的 Python 和 C++ 和使用 Windows 窗体的 C# (.NET 1) 的经验。
回答by fabrizioM
Go For PyQt:
去PyQt:
http://www.riverbankcomputing.co.uk/software/pyqt/download
http://www.riverbankcomputing.co.uk/software/pyqt/download
Download The Qt Developers toolto generate the gui automatically
下载Qt Developers 工具自动生成 gui
www.qtsoftware.com/products/developer-tools
www.qtsoftware.com/products/developer-tools
For schema validation try lxml
对于架构验证尝试lxml
回答by Richard B
I'm not exactly sure if I can be completely of help to you @Adrian, but I've been researching something very close to what you are discussing...
我不确定我是否可以完全帮助你@Adrian,但我一直在研究与你正在讨论的非常接近的东西......
Using something like Linq to XML may assist you in the validation of the data being entered, as there are already methods that will validate the data for you.
使用 Linq to XML 之类的东西可以帮助您验证输入的数据,因为已经有一些方法可以为您验证数据。
As I recall, there are a few tools that allow you dynamically create the app... link
我记得,有一些工具可以让您动态创建应用程序...链接
Hope this helps.
希望这可以帮助。
回答by StackedCrooked
One solution could be to write an XSL transformation that converts the XML file into a XAML file.
一种解决方案可能是编写一个 XSL 转换,将 XML 文件转换为 XAML 文件。
回答by alisami
If the GUI will be simple and you don't bother about the geometry of the components(widgets) in the dialogs, Qt will be a good option. Actually I'm working on a similar task for my project, and my goal was to validate the form data by using an XML file.
如果 GUI 很简单并且您不关心对话框中组件(小部件)的几何形状,Qt 将是一个不错的选择。实际上,我正在为我的项目执行类似的任务,我的目标是使用 XML 文件验证表单数据。
Using Qt, it is possible to access any widget on the dialog at run-time by using its object name. So that validation can be applied to the dialog contents.
使用 Qt,可以在运行时通过使用其对象名称访问对话框上的任何小部件。这样验证就可以应用于对话框内容。
Creating any dialogs will be even easier, since you will have the widget type and certain information and using layouts, fascinating results can be obtained.
创建任何对话框将更加容易,因为您将拥有小部件类型和某些信息并使用布局,可以获得迷人的结果。
回答by BigJump
It's worth taking a look at Jaxfrontwhich is able to consume an XSD and generate a form (including HTML). You can also supply an instance XML document for it to load into the GUI, and save out instance XML documents too.
这是值得考虑看看Jaxfront是能够消耗的XSD和产生形式(包括HTML)。您还可以提供一个实例 XML 文档以将其加载到 GUI 中,并保存实例 XML 文档。
I tried it with one of our fairly complicated XSD's and it worked pretty well.
我用我们相当复杂的 XSD 之一进行了尝试,效果很好。
Sadly it's written in Java - I'm still looking for something which can generate .NET web forms or XAML/WPF! In fact even XFORMS would be good.
遗憾的是它是用 Java 编写的——我仍在寻找可以生成 .NET Web 表单或 XAML/WPF 的东西!事实上,即使是 XFORMS 也不错。
回答by Cornelius Schumacher
There is an experimental tool, which does that, automatically create a desktop UI for handling data stored in XML. It's called KXForms. It comes as part of a suite of tools for handling XML data in various ways, like creating C++ code from an XML schema to represent the data natively in C++ and encapsulate parsing and writing.
有一个实验性工具可以自动创建桌面 UI 来处理存储在 XML 中的数据。它被称为KXForms。它是一套工具的一部分,用于以各种方式处理 XML 数据,例如从 XML 模式创建 C++ 代码以在 C++ 中本地表示数据并封装解析和写入。
This might not be the production-ready solution you are looking for, but it's a start and a source for inspiration. It's open source, so contributions are certainly welcome.
这可能不是您正在寻找的生产就绪解决方案,但它是一个开始和灵感来源。它是开源的,因此当然欢迎贡献。
回答by Andrew Swan
"XAmple XML Editorproject introduces a java Swing based XML editor that analyzes a given schema and then generates a document-specific graphical user interface. Unlike other XML editors, the XAmple XML editor GUI exposes not just a tree representation of the XML document but rather a logical combination of the XML document and respective XML Schema. The user interface of the XML editor is highly logical and intuitively comprehensible. To be able to prepare valid XML documents of significant complexity, a user is not required to be familiar with XML and XML Schema languages and to have any a-priori knowledge about the documents structural requirements."
" XAmple XML Editor项目引入了一个基于 java Swing 的 XML 编辑器,它分析给定的模式,然后生成特定于文档的图形用户界面。与其他 XML 编辑器不同,XAmple XML 编辑器 GUI 不仅公开 XML 文档的树表示,而且XML 文档和相应 XML 模式的逻辑组合。XML 编辑器的用户界面具有高度的逻辑性和直观的可理解性。为了能够准备非常复杂的有效 XML 文档,用户不需要熟悉 XML 和 XML模式语言,并具有有关文档结构要求的任何先验知识。”
I've tried it and even my non-technical boss likes it. You can use it as-is or use it as a library upon which to base your own Java-based UI.
我已经尝试过了,甚至我的非技术老板也喜欢它。您可以按原样使用它,也可以将其用作库,以此作为您自己的基于 Java 的 UI 的基础。