views:

479

answers:

1

First of all, i am new to this topic, and after gathering a lot of background information i grew even more confused.

I've got a few classes, all of them are serializable, some implement IXmlSerializable. The classes are tagged with [XmlRoot], [XmlAttribute] and so on in the appropriate places.

What i am wondering about is how to create a simple XSD for each class, using the existing tags. I'm interested in both the manual and the programmatic way. If possible, i'd prefer to use tools integrated in VS2008.

+3  A: 

Well, with IXmlSerializable all bets are off, as no schema is guaranteed. However, for the rest:

xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]

From MSDN:

/t[ype]:typename Specifies the name of the type to create a schema for. You can specify multiple type arguments. If typename does not specify a namespace, Xsd.exe matches all types in the assembly with the specified type. If typename specifies a namespace, only that type is matched. If typename ends with an asterisk character (*), the tool matches all types that start with the string preceding the *. If you omit the /type option, Xsd.exe generates schemas for all types in the assembly.

...

Classes to XSD Generates an XML schema from a type or types in a runtime assembly file. The generated schema defines the XML format used by System.Xml.Serialization.XmlSerializer.

Marc Gravell
is it possible to include xsd.exe in the build process for a class?
mafutrct
You can certainly include it in your build script, but it would have to run after the assembly has built... there are lots of ways of executing an exe after successful build.
Marc Gravell
Sure - but what's the point of re-generating the classes over and over and over again, if nothing changes??
marc_s
I'm not generating classes. My idea was that i don't have to call xsd.exe for every single class manually.
mafutrct
@mafutrct - you don't have to - you can use wildcards (*) or namespaces to get xsd from all your classes in a single hit. As per the quoted section.
Marc Gravell
Only a subset of all classes in the project is compatible with xsd.exe, and xsd.exe fails for all classes as soon as even one of them cannot be processed.
mafutrct