如何在 C# 中以编程方式创建 XSD 文件? [英] How to create XSD file programmatically in C#?

查看:27
本文介绍了如何在 C# 中以编程方式创建 XSD 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 xml 文件(我使用 XmlDocument 在 c# 中创建的),现在我必须在 C# 中以编程方式创建对应于它的 xsd 文件......我该怎么做?我可以使用相同的类来创建 xml 文件吗?或者我应该使用任何其他(xsd 相关)类吗?

I have a xml file (that i created in c# using XmlDocument) and now i have to create xsd file the corresponds to it also programmatically in C# ... how can I do this ?? can I use the same classes for creating xml files ? or are there any other (xsd related) classes I should use ??

推荐答案

虽然 XML Schema 文件是一个 XML 文件,但它的某些事情可能会使手动"完成它变得很麻烦;有人可能会说为什么使用 DOM API 而不是使用由 XSD.exe 或 XSD2Code.exe 生成的 C# 类来编写 XML?或者稍微推动一下……有点类似于有人说 C# 语句最终会变成 IL 程序集;为什么不写IL呢?

While an XML Schema file is an XML file, it has certain things that could make it cumbersome to do it "by hand"; one could say why write XML using the DOM API instead of using C# classes generated by XSD.exe or XSD2Code.exe? Or to push it a bit... somewhat similar to someone saying C# statements eventually turn into IL assembly; why not write IL instead?

Schema Object Model API 提供了另一种选择;在 .NET 中,它是 System.Xml.Schema 命名空间.

Another alternative is provided by the Schema Object Model API; in .NET, it is the System.Xml.Schema namespace.

看看这里的代码示例MSDN.它会给你另一种方法的想法.它提供了一个程序员友好的 API 来生成 XSD,而不是处理实际的 XML.

Take a look at the code example found here on MSDN. It'll give you an idea for another approach. It provides a programmer friendly API to generate XSDs, instead of dealing with the actual XML.

这篇关于如何在 C# 中以编程方式创建 XSD 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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