Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating XML schema and auto-generate the serializable class out of it using Visual Studio 2010

I am trying to create an XML schema to be serialized/deserilized using visual studio 2010, but it looks really complicated having an xml file and another xml schema file, I didn't get how it should be done. I rememeber in visual studio 2005 it was much simpler by just creating xml file and open it with the xml designer then draw the schema, then generate the serializable code out of the schema. Any hint/ link that would help in doing the same using Visual Studio 2010 professional.

like image 398
Emo Avatar asked May 29 '12 08:05

Emo


1 Answers

Let me try to answer this:

  1. open your VS project.
  2. open the XML on your project.
  3. On VS, go to the menu tab and click on create schema
  4. save the schema file and added to your project.

Then you can create your own class for the serialize/deserialize process or use xsd.exe

I used the last one. In my case I can found the tool in the \Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\xsd.exe.

Then you can open CMD or the Visual Studio command window and write something like: xsd.exe [THE XSD FILE] /c /l:c# /o:[DIRECTORY WHERE YOU WANT TO SAVE THE .CS]

I hope this works for you or answer your question. Pretty much I used the same approach with VS 2008 and 2010.

Here are related topics just in case:

XSD tool: https://docs.microsoft.com/en-us/dotnet/standard/serialization/xml-schema-definition-tool-xsd-exe

XML Serialization and Schema without xsd.exe

Generate classes from XSD

if you don't have the Microsoft SDK you can get it from: https://docs.microsoft.com/en-us/dotnet/core/sdk

like image 134
Carlos G. Avatar answered Sep 24 '22 10:09

Carlos G.