Friday, April 1, 2011

validate large XML file



Recently, I got a requirement to validate a large XML file almost 1000000 lines.

Here is a sample code to do that against

       
class SampleXMLValidation

{

 [STAThread]

 static void Main(string[] args)

 {

  // Read the file.

  XmlTextReader Reader = new XmlTextReader("MyFile.xml");

  XmlValidatingReader validater = new XmlValidatingReader(Reader);
  //Schema Validator

  validater.ValidationType = ValidationType.Schema;

  validater.ValidationEventHandler += new ValidationEventHandler

  (ValidationHandler);

  while (validater.Read());

  Console.WriteLine("Validation was successful...No Errors ");

  Console.Read();

 }

 public static void ValidationHandler(object sender,

 ValidationEventArgs args)

 {

  Console.WriteLine("Validation Error");

  Console.WriteLine("\tSeverity:{0}", args.Severity);

  Console.WriteLine("\tMessage :{0}", args.Message);

  Console.Read();

 }

}

}
       
 

If we want to validate online, Here is a good link for that

No comments:

Post a Comment