Hi Ravindranath.net,
You can validate a XML against a XSD using the
Validate
extension method.
Here is the code showing how to do it.
XmlSchemaSet schemaSet = new XmlSchemaSet();
DirectoryInfo dir = new DirectoryInfo("<path where="" you="" have="" your="" xsd="" files="">");
foreach (FileInfo fileInfo in dir.GetFiles("*.xsd"))
{
schemaSet.Add(null, fileInfo.FullName);
}
XDocument docToValidate = XDocument.Load("<path of="" xml="" you="" want="" to="" validate="">");
string validationMessage = string.Empty;
docToValidate.Validate(schemaSet, (o, e) =>
{
validationMessage += e.Message + Environment.NewLine;
});
return validationMessage;</path></path>
This code may need some customization to meet your requirements. Hope this helps.