Generate C# class from XML

后端 未结 8 1726
青春惊慌失措
青春惊慌失措 2020-11-22 05:19

Can I generate a C# class from an XML file?

8条回答
  •  清酒与你
    2020-11-22 05:42

    Yes, by using 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'.
    

    Notes

    Answer how to change directory in Developer Command Prompt to d:\temp may be useful.

    If you generate classes for multi-dimensional array, there is a bug in XSD.exe generator, but there are workarounds.

提交回复
热议问题