gpt4 book ai didi

c# - 如何使用 xsd.exe/c 输出

转载 作者:数据小太阳 更新时间:2023-10-29 01:45:23 30 4
gpt4 key购买 nike

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

有没有一种简单的方法可以将此类的实例化为 XML 字符串?

最佳答案

super 简单。我喜欢 xsd 工具。我在下面采取了一些自由。

//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);

关于c# - 如何使用 xsd.exe/c 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232182/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com