如何使用 xsd.exe/c 输出 [英] How to use xsd.exe /c output

查看:32
本文介绍了如何使用 xsd.exe/c 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 xsd.exe 将 .xsd 文件转换为 C# 类.它有效,但我仍然不太确定如何使用这个类.它有几个类级别的属性,但最有趣的是 System.Xml.Serialization.XmlTypeAttribute.哪个类使用该属性?

I tried using xsd.exe to convert an .xsd file into a C# class. It worked, but I'm still not quite sure how to use this class. It has several class-level attributes but the most interesting is System.Xml.Serialization.XmlTypeAttribute. Which class uses that attribute?

有没有简单的方法可以把这个类的实例化成一串XML?

Is there a simple way to turn an instantiation of this class into a string of XML?

推荐答案

超级简单.我喜欢 xsd 工具.我在下面采取了一些自由.

Super straight-forward. I love the xsd tool. I have taken some liberties below.

//From xml to object
YourRootType inst = new XmlSerializer(typeof(YourRootType)).Deserialize(XmlReader.Create("some.xml"));

//From object to xml
Using(FileStream fs = new FileStream("some.xml", FileMode.Create))
   new XmlSerializer(typeof(YourRootType)).Serialize(fs, inst);

这篇关于如何使用 xsd.exe/c 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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