我在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工具,我得到以下类。要使用它们,我必须添加属性[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;}
}
}
}