使用 Visual Studio 2010 创建 XML 架构并从中自动生成可序列化的类 [英] Creating XML schema and auto-generate the serializable class out of it using Visual Studio 2010

查看:32
本文介绍了使用 Visual Studio 2010 创建 XML 架构并从中自动生成可序列化的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Visual Studio 2010 创建一个要序列化/反序列化的 XML 模式,但是拥有一个 xml 文件和另一个 xml 模式文件看起来真的很复杂,我不知道应该怎么做.我记得在 Visual Studio 2005 中,只需创建 xml 文件并使用 xml 设计器打开它,然后绘制架构,然后从架构中生成可序列化的代码,这要简单得多.任何有助于使用 Visual Studio 2010 Professional 执行相同操作的提示/链接.

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. 打开你的 VS 项目.
  2. 在您的项目中打开 XML.
  3. 在 VS 上,转到菜单选项卡并单击创建架构
  4. 保存架构文件并添加到您的项目中.

然后您可以为序列化/反序列化过程创建自己的类或使用 xsd.exe

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

我用了最后一个.就我而言,我可以在 Program Files (x86)Microsoft SDKsWindowsv7.0ABinxsd.exe 中找到该工具.

I used the last one. In my case I can found the tool in the Program Files (x86)Microsoft SDKsWindowsv7.0ABinxsd.exe.

然后您可以打开 CMD 或 Visual Studio 命令窗口并编写如下内容:xsd.exe [XSD 文件]/c/l:c#/o:[您要保存 .CS 的目录]

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]

我希望这对您有用或回答您的问题.在 VS 2008 和 2010 中,我几乎使用了相同的方法.

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

以下是相关主题以防万一:

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

没有 xsd.exe 的 XML 序列化和架构

从 XSD 生成类

如果您没有 Microsoft SDK,您可以从以下位置获取它:https://docs.microsoft.com/en-us/dotnet/core/sdk

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

这篇关于使用 Visual Studio 2010 创建 XML 架构并从中自动生成可序列化的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆