Trygve
Trygve

Reputation: 2531

Generate XSD from types in assembly with xsd.exe, having dataannotation attributes on properties

I was hoping to reuse some viewmodel classes with dataannotations to generate xsd files for the purpose of validating (and documenting) xml files from 3rd party systems. Xsd.exe generates the .xsd files fine, but dataannotation attributes like [Required] are not reflected in the xsd with f.ex. minOccurs=1.

What options (if any) do I have here? The "easiest" would probably be to create my own xsd generation using reflection. Or could I get away with just creating the extra validation attributes in a separate xsd and use both when validating xml files towards it?

Any other ideas?

Upvotes: 5

Views: 713

Answers (1)

MiMo
MiMo

Reputation: 11983

I don't know of any other solution.

I did write an XSD generator using reflection (to be able to include comments in my case) - it is quite a lot of work but definitely feasible.

Upvotes: 1

Related Questions