.xsd validation of c# property

There may not be any real world use for this but i was wondering if its possible to validate a property against the xsd. I generated a cs file from the schema using xsd.exe but none of the validation logic was carried over for instance...\[code\]<xsd:element type="Text_Key" name="LPI_Key"/></xsd:simpleType> <xsd:simpleType name="Text_Key"><xsd:restriction base="xsd:string"> <xsd:length value="http://stackoverflow.com/questions/10651249/14" fixed="true"/> <xsd:pattern value="http://stackoverflow.com/questions/10651249/[0-9][0-9][0-9][0-9][LXC][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/></xsd:restriction>Generatesprivate string lPI_KeyField;\[/code\]Maybe im missing something but i would have thought this to be possible. I know i can validate if i then convert the property to xml but this seems a bit of a backwards step and as i said it may not be of any real use but it seems to make sence that if validation logic already exists why not use it. The reason id validate on the property is so i can inform the user as they are typing in the value that something is wrong, instead of waiting till all values are entered and they hit submit before converting to xml and validating. Hopefully this makes sence and if i have missed any obvious tutorials or anything i wanted to say i have googled but all i got back was 'validate xml against xsd', Sometimes just knowing the keywords makes all the difference in a google search though. Responce to Romil:thanks for the responce. Although i will agree that RegEx would perform the required validation, if the xsd.exe would generate that for you it would be great. but as seen in my original post no validation is carried over, you could say im just being lazy but i see it as trying to reduce accidents and confusion. Using one set of validation rules through out the application, datastore and so on, would mean that no validation errors would prohibit the user (in the case above the xml schema is a predefined schema that i have no control over and im sure this is a case that many people would relate too). if i was to write my own regex validation (And the schema im using as a point of reference is a very large one) and the xsd validation rules where to change, i would then have to update all the changes in my regex ( bearing in mind that the original RegEx may then prevent users entering valid data untill the update is performed ). Now if i was able to validate against the xsd directly it would just be a matter of swapping the old one out and placing the new one in ( for the purposes of this question we can assume that only the validation logic changed ;-)) and after all the value of the property is still the same value that would be in an xml string.
 
Back
Top