Simple C# XML Schema Validation

While working I’ve often had to deal with data being sent in XML. Specifically, working on web services which are constantly passing it around. This data usually needs to be marshaled into some domain objects to continue working, but sometimes the data being sent is no good. One solution I found to fail early when encountering bad XML was validating it against it’s schema. I’m not sure if there are simpler ways, but this is how I was able to do it in C#: public string IsValidXml(string xmlString, string schemaPath) { if (string.IsNullOrWhiteSpace(xmlString)) { throw new ArgumentNullException(“xmlString”); } if (string.IsNullOrWhiteSpace(schemaPath)) { Continue reading Simple C# XML Schema Validation