Generate C# class from XML

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

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

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 05:26

    You can use xsd as suggested by Darin.

    In addition to that it is recommended to edit the test.xsd-file to create a more reasonable schema.

    type="xs:string" can be changed to type="xs:int" for integer values
    minOccurs="0" can be changed to minOccurs="1" where the field is required
    maxOccurs="unbounded" can be changed to maxOccurs="1" where only one item is allowed

    You can create more advanced xsd-s if you want to validate your data further, but this will at least give you reasonable data types in the generated c#.

提交回复
热议问题