Alex J
Alex J

Reputation: 10205

How do I get schema information for a node in a XmlDocument?

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.

Upvotes: 1

Views: 227

Answers (1)

bill seacham
bill seacham

Reputation: 395

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

Upvotes: 1

Related Questions