2

I use Xsd2Code in VS 2012 to generate classes from a xsd file. First I create a xsd File from the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Students>
  <Student>
    <RollNo>1</RollNo>
    <Name>Student 1</Name>
    <Address>Xyz Street</Address>
  </Student>
</Students>

Then I use the result (xsd file) for the Xsd2Code tool and I get the following classes. To use them I have to add the Attribute [XmlElement("Student")]. Are there some settings in the Xsd2Code menu, so that it will generate output where I do not have to edit the class files?

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;}
        }
    }
}
Kemal Kefeli
  • 2,276
  • 2
  • 18
  • 22
user3206010
  • 141
  • 2
  • 16

0 Answers0