從class產生xsd(xml schema)檔案

來源:互聯網
上載者:User

最近一個開放API項目中,需要以xml形式向第三方提供結果。由於是開放介面,需要同時提供xml schema(xsd),所以不得不花了些時間學習xsd,然後手工編寫。後來發現原來.NET Framework提供了從class自動產生xsd檔案的工具: xsd.exe。對於不熟悉xsd的朋友,提供了一個編寫xsd的捷徑便是:先編寫class,編譯成dll/exe,然後通過xsd.exe產生對應的xsd檔案。

下面簡單介紹xsd.exe的用法:

(1) 開啟.net framework sdk命令列(我的路徑是:D:\"Program Files"\Microsoft Visual Studio 8"SDK"\v2.0)

(2) 輸入"xsd -h"查看協助,從class到xsd相關的部分:xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]

(3) 根據協助運行命令"xsd.exe sample.dll /type:MyClass"

註:class需要一些條件,如可序列化,有預設建構函式,否則運行命令是會報錯。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.