ASP.NET 中表单的 XSD 元素
是否有一种标准方法将 XSD 转换为输入表单(ASP.NET C#),以便以后每当从 XSD 添加/删除新字段时,页面上的字段会自动显示或分别消失,这是吗?需要内部开发我认为必须有一种方法来序列化/反序列化并生成表单? 任何他将不胜感激..
Is there a standard way to convert an XSD to an input form (ASP.NET C#) so that later on whenever a new field is added / removed from the XSD the field on the page automatically shows up or goes away respectively, is this something which needs to be developed in-house I assume there must be a way to serializes / deserializes and generates a form? Any hel would be appreciated..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为没有任何内置的东西可以使其完全自动化。 然而,你可以非常接近。 Visual Studio 包含一个名为 xsd.exe 的命令行程序,您可以使用该程序从 xsd 文档自动创建类定义。 一旦有了该类定义,您就可以通过 ObjectDataSource 组件和 DetailsView 控件将其连接到表单。
I don't think there's anything built in to make this fully automatic. However, you can get pretty close. Visual Studio includes a command line program called xsd.exe that you can use to automatically create a class definition from an xsd document. Once you have that class definition you can connect it to a form via an ObjectDataSource component and a DetailsView control.
假设:您使用 XML 是因为目前它对您来说更简单。
想法:既然您想要创建一个表单来操作数据,我猜您可能会接受 SQL 而不是 XML。 情况可能并非如此,但如果您有数据库后端而不是 XML/XSD 后端,您可能会找到更多工具来帮助您。 (此外,还有多种方法可以将数据从一种数据转换为另一种数据)。
有一些工具可以从 ASP.NET 中的数据库创建表单。 例如,SubSonic 有一个自动脚手架模块,可让您创建仅了解其架构的数据库管理器。 如果架构发生变化,只需让 SubSonic 重新生成其文件,您的表单就会被修改。 它并不完美,但可能会大有帮助,具体取决于您的需求。
选项 1) 您可以从 XSD 创建数据库架构(如何我可以从 XSD 文件创建数据库表吗?)并从那时起使用 SubSonic。 这可能比你原来的问题更痛苦......只有你知道。
选项 2) 破解 SubSonic 脚手架,使其支持底层 XSD/XML 而不是数据库。 您可以重复使用他们的许多基础设施(SubSonic 是开源的)来从 XSD 生成表单。
祝你好运!
Assumption: You're using XML because it is simpler for you at the moment.
Idea: Since you want to create a form to manipulate the data, I'm guessing you might be open to SQL instead of XML. This may not be the case, but you will probably find more tools to help you if you have a database backend instead of an XML/XSD backend. (Plus there are ways you can convert your data from one to another).
There are tools that create forms from databases in ASP.NET. SubSonic, for example, has a auto-scaffolding module that lets you create a database manager knowing only its schema. If the schema changes, just have SubSonic regenerate its files and your forms will have been modified. It isn't perfect, but it may go a long way, depending on your needs.
Option 1) You can create the database schema from the XSD (How can I create database tables from XSD files?) and use SubSonic from that point on. This may be even more of a pain than you original question... only you know.
Option 2) Hack the SubSonic scaffolding so that it supports your underlying XSD/XML instead of a database. You can probably re-use lots of their infrastructure (SubSonic is open source) to generate the form from an XSD.
Good luck!
好吧,我不得不说 ObjectDataSource 不是一个坏主意,但是如果您有嵌套元素,则这不起作用。 除此之外,对于嵌套元素,您还将在 DetailsView 中拥有所有“..FieldSpecified”布尔字段。
我仍在尝试弄清楚如何使用 XSD 文件生成 ASP.NET 表单,而不必输入所有内容,这简直就是猴子的工作。
有人已经遇到过这个问题了吗?
PS:另一种方法是使用 InfoPath,但这需要许可软件才能作为 Web 表单运行......
Well, I have to say that the ObjectDataSource is not a bad idea, but this does not work if you have nested elements. On top of this, for nested elements you will have all the "..FieldSpecified" boolean fields in the DetailsView as well.
I'm still trying to figure out how to generate a ASP.NET form using an XSD file, without having to type in everything, which is monkey work.
Anyone already ran into that issue?
PS: An other approach would be to use InfoPath, but this requires licensed software to run as webforms...