2) Name the file as employeeInfo.xml.
3) This tool can be primarily used to generate xml schema file (.xsd) from an xml data file (.xml). The following command generates
employeeinfo.xsd from employeeinfo.xml :
xsd.exe employeeinfo.xml
You should get a message
Writing file 'C:\xsd\employeeinfo.xsd'.
4) To explore all the options of xsd.exe type xsd /?
5) This tool can also be used to generate xml serialization classes and datasets. Now we will generate employeeinfo class and
dataset.
6) To generate a class from schema give /c option and to generate dataset use /d option
xsd.exe employeeinfo.xsd /c // to generate xml serilization class
xsd.exe employeeinfo.xsd /d // to generate dataset
You should get a message
Writing file 'C:\xsd\employeeinfo.cs'.
7) Xsd.exe is also used to generate schema of types present in comlied assemblies.
8) Let us generate our employeeinfo class with the /c option as shown below and then add this class to a class library and regenerate schema of the class from its dll
9) Generate the class with the following command xsd.exe employeeinfo.xsd /c . If you are a VB.Net person than you can use the
/l:VB option with it to generate the class in VB.
10) Open a new class library project (C# or VB). Add this class to the project, compile the project and create the dll.
11) Now to generate schema of a type from a compiled assembly :
xsd <Your Dll Name>.dll e.g. xsd EmployeeInfoLib.dll
This will generate the schema of the various types present in the dll since we have only one class you should get a message
Writing file 'C:\xsd\schema0.xsd'.
12) To generate schema of any type from a complied assembly the class should be marked with xmlrootattribute. If you look at the
employeeinfo class that we added to the assembly you will notice xmlroot attribute right at the top of the class declaration.
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute("employeeInfo", Namespace="", IsNullable=false)]
public class employeeInfo {
Only classes marked with xmlroot attribute will be recognized by xsd.exe.
13) If you want to generate schema for any particular type in the assembly you can use the /type option. We can generate schema of employee address as follows:
xsd <Your Dll Name>.dll /type:rootEmployeeAddress /// check the name in the class.
I hope these articles that I am posting help all of us. If you have any doubts/sugegstions/improvements/queries etc. please post them I may not be in a position to reply them immediately as I am working .... but you will definitely get an answer sooner or later.
-- Please post your queries and comments for my articles in the usergroup for the benefit of all. I hope this step from my end is helpful to all of us.
Regards,
Namratha (Nasha)