简体   繁体   中英

How to programmatically generate .NET classes from XSD? (Like xsd.exe do)

我想以 xsd.exe 方式而不是linq toxsd 方式生成类。

Look at the System.Xml.Serialization.XmlCodeExporter class.

UPDATE (in case John Saunders didnt bother reading further)

"Xsd.exe uses XmlCodeExporter to generate classes from XML Schema Definition (XSD) documents."

Try Xsd2Code

Seems to be the best free/Open source tool out there.

Good integration with VS2010

It's working great for me.

You can call xsd.exe from your code using Process Class . I did it once and its fast and straightforward. You won't need to bored much :).

Which part of the process do you not know how to do?

You can load one or more instances of the XmlSchema class into an XmlSchemaSet . This will allow you to programmaticly examine all parts of the schema and other schemas it may reference. You can use this information to generate code, either as text that will later need to be compiled, or else using the CodeDOM. See Dynamic Source Code Generation and Compilation .


If you are generating code in the context of Visual Studio, then I'd suggest you do so via T4 Templates. See Generating Artifacts By Using Text Templates .

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