0

I've got an XSD which I've turned into classes using the VS XSD.exe

The code will populate these classes before getting to a stage when I then want to validate that they are "correctly" populated - for example, if a field is mandatory in the XSD, but it is a string object in the generated class, will anything stop me from leaving it blank? - if nothing stops me it will be invalid! (Something like this question)

I'm trying to avoid generating my XML and then reading it back in and validating the actual XML against the XSD if this is at all possible. I want to know that the population of the classes has been done wrong before I even attempt to generate the XML.

Any thoughts or examples would be great!

There are lots of articles about validating XML against an XSD but I can't find anything helpful about validating the population of the generated classes against an XSD. I don't know if this is possible!

Community
  • 1
  • 1
Danny Lager
  • 371
  • 1
  • 4
  • 17

1 Answers1

0

xsd.exe will add some extra boolean properties (for example: thisStringSpecified) which you can use for validating mandatory strings.

myClass.ThisStringSpecified = string.IsNullOrEmpty(ThisString);

You can test it afterwards by Serializing the object and use the XSD to validate it (if you want to be really sure).