Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 295
Trygve Avatar asked Nov 13 '22 06:11

Trygve


1 Answers

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.

like image 156
MiMo Avatar answered Jan 10 '23 15:01

MiMo