从XML生成C#类

18 浏览
0 Comments

从XML生成C#类

我能从XML文件中生成一个C#类吗?

admin 更改状态以发布 2023年5月21日
0
0 Comments

是的,可以通过使用 xsd.exe 来实现。

D:\temp>xsd test.xml
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'D:\temp\test.xsd'.
D:\temp>xsd test.xsd /classes
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'D:\temp\test.cs'.

注意:

回答如何在开发人员命令提示符中更改目录到 d:\temp可能会很有用。

如果您为多维数组生成类,则 XSD.exe 生成器存在错误,但存在解决方法

0
0 Comments

如果你正在VS2012(或更高版本)的.NET 4.5项目中工作,你可以直接将XML文件作为类进行特殊粘贴

  1. 将XML文件的内容复制到剪贴板中
  2. 在编辑器中,选择你想粘贴类的位置
  3. 从菜单中选择 编辑 > 粘贴特殊 > 粘贴XML作为类
0