I'd like to generate the classes the xsd.exe way and not the linqtoxsd way.
-
1Why wouldn't you use xsd.exe?vgru– vgru2009-07-01 09:52:36 +00:00Commented Jul 1, 2009 at 9:52
-
Perhaps does not want to, what is it to you?leppie– leppie2009-07-01 09:54:33 +00:00Commented Jul 1, 2009 at 9:54
-
1@leppie: it would clarify the requirements. For instance, does he have a restriction to not call external programs? To not use Microsoft programs?John Saunders– John Saunders2009-07-01 09:56:31 +00:00Commented Jul 1, 2009 at 9:56
-
@leppie: wouldn't the simplest solution be to call xsd? One line of code? (KISS/you ain't gonna need it)vgru– vgru2009-07-01 10:11:35 +00:00Commented Jul 1, 2009 at 10:11
-
One of the reason against XSD is that is STILL to this day doesn't support List<T> - it still always creates T[] which is just plain horrible.marc_s– marc_s2009-07-01 11:12:20 +00:00Commented Jul 1, 2009 at 11:12
4 Answers
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."
10 Comments
Try Xsd2Code
Seems to be the best free/Open source tool out there.
Good integration with VS2010
It's working great for me.
Comments
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 :).
Comments
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.