C# 中的 Jaxb 等价物
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/765422/
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
Jaxb equivalent in C#
提问by mgamer
Using JAXB in Java it is easy to generate from a xml schema file a set of Java classes that xml conforming to that schema can be deserialized to.
在 Java 中使用 JAXB 很容易从 xml 模式文件生成一组 Java 类,符合该模式的 xml 可以反序列化为。
Is there some C# equivalent of JAXB? I know that Linq can serialize and deserialize classes to/from xml files. But how can I generate C# classes from xml schema file and then use this classes with linq?
是否有一些 C# 等价于 JAXB?我知道 Linq 可以在 xml 文件中序列化和反序列化类。但是如何从 xml 模式文件生成 C# 类,然后将这些类与 linq 一起使用?
采纳答案by John Feminella
If you're using Visual Studio,try the XML Schema Definition Tool. It takes your schema definitions and produces C# classes -- or it can go the other way and produce schema definitions from classes. It also has a number of other XML-related transformations.
如果您使用的是 Visual Studio,请尝试使用XML 架构定义工具。它接受您的架构定义并生成 C# 类 —— 或者它可以采用另一种方式并从类生成架构定义。它还具有许多其他与 XML 相关的转换。
回答by Cheeso
There is a better tool from Microsoft called XsdObjectGen, the XSD Object Code Generator. It is like xsd.exe, but better. Also free, it is not part of the .NET SDK, but is a separate download.
Microsoft 有一个更好的工具,称为XsdObjectGen,即 XSD 对象代码生成器。它类似于 xsd.exe,但更好。同样免费,它不是 .NET SDK 的一部分,而是单独下载。
Also see the SO question: XSDObjectGen vs Xsd.exe
另请参阅 SO 问题:XSDObjectGen vs Xsd.exe
回答by User1
Look into using DataSet. It's a bit of a different concept from using "Java Beans". The entire XML document is treated hierarchical set of tables all in a single class. The good part is that theory of encapsulation for OOP is actually enforced. Wow, Microsoft got something right that Sun pooched.
研究使用数据集。这与使用“Java Beans”有点不同。整个 XML 文档都被视为单个类中的分层表集。好的部分是 OOP 的封装理论实际上得到了执行。哇,微软做对了 Sun 挖出来的东西。
Anyway. You can also look at typed DataSet's if you want make things more interesting. I've used this on major projects with great success.
反正。如果您想让事情变得更有趣,您还可以查看类型化数据集。我已经在重大项目中使用了它,并取得了巨大的成功。