简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM