Use XML schema to validate XML documents : Schema : XML C# Source Code


Custom Search

C# Source Code » XML » Schema »

 

Use XML schema to validate XML documents








    

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Validate {
  public static void Main(string [] args) {

    using (Stream stream = File.OpenRead(args[0])) {
      XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(stream));
      reader.ValidationType = ValidationType.Schema;
      reader.Schemas.Add("", args[1]);
      reader.ValidationEventHandler += new ValidationEventHandler(Handler);

      while (reader.Read()) {
      }
    }
    Console.WriteLine("Document is valid.");
  }

  public static void Handler(object sender, ValidationEventArgs e) {
    Console.WriteLine(e.Message);
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo XML
» Schema