C# How to create XSD & Class file using Command prompt for C# XmlSerializer


C# How to create XSD & .Net Class file using Command prompt for C# XmlSerializer

There are various ways to create & read xml files. Usually we create a class & read it using xdocument or xmldocument. For that we need to create declare variables for the class & use GET SET method. Another alternative is to create XSD file from XML using XSD.EXE tool. From the XSD, we can create .Net class file which can read your XML data using class XmlSerializer.

Use xsd.exe to create xml & class file

This tool will create XSD & Class file instantaneously, without a single line of code . Lets see how can you do it.

  1.     Suppose you have file in folder. C:\TEST & you have a file LinkData.xml in it.
  2.     Open Visual Studio Command prompt from the menu.
  3.     Type C:\>cd C:\TEST  & press ENTER to set the current directory.
  4.     Type  C:\TEST>xsd.exe LinkData.xml
  5.     This will create XSD file of your XML file in the same directory.
Create xsd from xml file using xsd.exe tool

Create the .net Class file for reading xml data

  1.     Now type  xsd.exe /classes /namespace:myClass LinkData.xsd
  2.     Replace myClass by the namespace of project in which you will be adding the class file.
  3.     It will create a class file with myClass namespace in it.
So, Finally you will have 3 files in your folder. First is your XML file, second XSD & the class file. Add class file to your project & use it.

Create.net class file from xsd.exe

C# How to create XSD & .Net Class file using Command prompt for C# XmlSerializer

There are various ways to create & read xml files. Usually we create a class & read it using xdocument or xmldocument. For that we need to create declare variables for the class & use GET SET method. Another alternative is to create XSD file from XML using XSD.EXE tool. From the XSD, we can create .Net class file which can read your XML data using class XmlSerializer.

Use xsd.exe to create xml & class file

This tool will create XSD & Class file instantaneously, without a single line of code . Lets see how can you do it.

  1.     Suppose you have file in folder. C:\TEST & you have a file LinkData.xml in it.
  2.     Open Visual Studio Command prompt from the menu.
  3.     Type C:\>cd C:\TEST  & press ENTER to set the current directory.
  4.     Type  C:\TEST>xsd.exe LinkData.xml
  5.     This will create XSD file of your XML file in the same directory.
Create xsd from xml file using xsd.exe tool

Create the .net Class file for reading xml data

  1.     Now type  xsd.exe /classes /namespace:myClass LinkData.xsd
  2.     Replace myClass by the namespace of project in which you will be adding the class file.
  3.     It will create a class file with myClass namespace in it.
So, Finally you will have 3 files in your folder. First is your XML file, second XSD & the class file. Add class file to your project & use it.

Create.net class file from xsd.exe

Was that useful? Why not share it?

By: