我在 VS 2012 中使用 Xsd2Code 从 xsd 文件生成类。首先,我从以下 XML 创建一个 xsd 文件:
<?xml version="1.0" encoding="utf-8" ?>
<Students>
<Student>
<RollNo>1</RollNo>
<Name>Student 1</Name>
<Address>Xyz Street</Address>
</Student>
</Students>
然后我将结果(xsd 文件)用于 Xsd2Code 工具,得到以下类。要使用它们,我必须添加 Attribute [XmlElement("Student")]
。Xsd2Code 菜单中是否有一些设置,以便在我不必编辑类文件的地方生成输出?
namespace ConsoleApplication2
{
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
public partial class Students{
private List<StudentsStudent> studentField;
public Students(){
this.studentField = new List<StudentsStudent>();
}
[XmlElement("Student")]
public List<StudentsStudent> Student{
get{return this.studentField;}
set{this.studentField = value;}
}
}
public partial class StudentsStudent{
private byte rollNoField;
private string nameField;
private string addressField;
public byte RollNo{
get{return this.rollNoField;}
set{this.rollNoField = value;}
}
public string Name{
get{return this.nameField;}
set{this.nameField = value;}
}
public string Address{
get{return this.addressField;}
set{this.addressField = value;}
}
}
}