views:

67

answers:

1

Having a XmlDocument loaded with a XSD schema, how do I get the restrictions for a given node in the document?

I would like to iterate through the document, and automatically correct errors where possible (eg: truncate strings that are too long, remove empty nodes that shouldn't be, etc.)

I am doing this because xsd.exe does not take into account string length restrictions or differentiate between null and empty strings. I'm finding that doing this "post-processing" is simpler than manually trying to ensure these restrictions before serialization.

+1  A: 

The XmlSchemaValidator class gives you this information. Look at the GetExpectedParticles & GetExpectedAttributes methods of this class.

bill seacham
Thank you, that was it.
Ilia Jerebtsov