-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Nasha
Message 1 in Discussion

 Hey Group,   Today we will discuss Xsd.exe tool.   All of us know about xml 
serialization and deserialization. When we say xml serialization we mean to say 
that we convert an objects public properties into xml attributes and/or xml 
elements. You should use Binary Serialization techniques to archive private 
data of an object.   There is a tool in the .net framework which can help us 
creating xml serialization classes,datasets,xml schemas from various xml  
formats and even compiled assemblies.   1) Let us get started by creating an 
sample xml file containing employee information.       <employeeInfo>
     <employee>
      <empid>1</empid>
      <firstname>Namratha</firstname>
      <lastname>Shah</lastname>
      <sex>F</sex>
      <address>
       <street>1</street>
       <city>mumbai</city>
       <state>maharashtra</state>
       <pin>400056</pin>
       <country>India</country>
      </address> 
     </employee>
    </employeeInfo>   
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) 
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to