blog.easyciel.net author="Patrick Rabian" about="c#, sharepoint, biztalk, team system resources" more="news, samples, tips for .NET world's developers !"

Validate XML with XSD

Monday, 15 May 2006 06:45 by prabian

To validate an XML file with an XSD file, use this !

public static XmlDocument ValidateAndLoadXmlDocument(string xmlFilePath, string xsdFilePath)
{

XmlDocument xmlDoc;

XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.Schemas.Add(null, xsdFilePath);
xmlSettings.ValidationType = ValidationType.Schema;

XmlReader xmlReader = XmlReader.Create(xmlFilePath, xmlSettings);
xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);

return xmlDoc;

}

Use this for asynchronous validation :

xmlSettings.ValidationEventHandler += new ValidationEventHandler(YourValidationEventHandler);

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 21. 2008 01:09