如何在VS2010 WPF中将XSD文件转换为强类型数据集 [英] How do I turn an XSD file into a strongly typed data set in VS2010 WPF

查看:130
本文介绍了如何在VS2010 WPF中将XSD文件转换为强类型数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个较旧的.net(2003)程序转发给VS 2010.看起来我可能会被W​​PF卡住(如果那个话),因为我想要使用的一些工具是为此设计的而不是Windows窗体。旧程序将xml文件读入强类型数据集,我想再次这样做。我可以把xml带进去,为它创建一个架构,但那时我就被困住了。在Schema菜单下有一个项目,它从xsd文件创建一个强类型数据集。那已经过去了,我似乎无法找到如何做到这一点。所有帮助都很感激

I am trying to bring an older .net (2003) program forward to VS 2010. It also looks like I may be stuck (if that's the word) with WPF as some of the tools I want to use were designed for that and not Windows forms. The old program read an xml file into a strongly typed dataset, and I would like to do that again. I can bring the xml in, create a schema for it, but at that point I'm stuck. There use to be an item under the Schema menu that created a strongly typed data set from a xsd file. That is gone and I can't seem to find how to do this. All help appreciated

推荐答案

您不能使用XML Schema Definition创建数据,因为它不代表数据,而是代表元数据。它与XML数据有关,因为数据库模式与数据库数据有关。如果您确实需要表示meda数据的数据,则需要在表示元数据的某些程序结构中解析Schema Definition;它可以通过不同的方式完成,具体取决于您的决定。







请参阅对这个答案的评论。您只需要这个类: https:/ /msdn.microsoft.com/en-us/library/system.xml.schema.xmlschema%28v=vs.110%29.aspx [ ^ ]。



您需要实例化此类,并使用其实例读取XML Schema的一些实例:

https://msdn.microsoft.com/en-us/library/ms162681(v=vs.110).aspx [ ^ ] ,

https://msdn.microsoft。 com / en-us / library / 5y5eyz59(v = vs.110).aspx [ ^ ]。



然后你可以遍历该模式并生成一些代码,将模式属性映射到某些.NET数据类型的方式你觉得方便。在某些情况下,甚至可以使用 System.Reflection.Emit 生成整个程序集:

https://msdn.microsoft.com/en-us/library/system .reflection.emit%28v = vs.110%29.aspx [ ^ ]。



(最后一个选项意味着真正困难的工作这很难调试,熟悉IL和CIL,CLR模型和其他基础知识。)



-SA
You cannot create data out of XML Schema Definition, because it represent not data, but meta-data. It is related to XML data in the same was as database schema is related to the database data. If you really want data representing meda-data, you need to parse Schema Definition in some program structure representing metadata; it can be done in different ways, depending on your decisions.



Please see comments to this answer. All you need is this class: https://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschema%28v=vs.110%29.aspx[^].

You need to instantiate this class and, with its instance, read some instance of XML Schema:
https://msdn.microsoft.com/en-us/library/ms162681(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/5y5eyz59(v=vs.110).aspx[^].

Then you can traverse that schema and generate some code, mapping schema properties to some .NET data type the way you find convenient for you. In certain cases, it may even make sense to generate whole assemblies on the fly, using System.Reflection.Emit:
https://msdn.microsoft.com/en-us/library/system.reflection.emit%28v=vs.110%29.aspx[^].

(That last option would mean really difficult work which is hard to debug, good knowledge of IL and CIL, CLR model and other fundamentals.)

—SA


这篇关于如何在VS2010 WPF中将XSD文件转换为强类型数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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