問題描述
我正在嘗試使用 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:
- 打開你的 VS 項目.
- 在您的項目中打開 XML.
- 在 VS 上,轉到菜單選項卡并單擊創建架構
- 保存架構文件并添加到您的項目中.
然后您可以為序列化/反序列化過程創建自己的類或使用 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 架構并從中自動生成可序列化的類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!