Validate Schema for XDocument : XDocument « XML LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

public class MainClass
{
    public static void Main()
    {
        XDocument doc = XDocument.Load("xml file");
        XmlSchemaSet schema = new XmlSchemaSet();
        schema.Add(null, "schema file");
        ValidationEventHandler handler = new ValidationEventHandler(MyHandler);
        doc.Validate(schema, handler);
    }

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

}








31.1.XDocument
31.1.1.Save and Load XML
31.1.2.LINQ To XML Element Text
31.1.3.Use Tree to display xml document
31.1.4.Binding xml to DataGridView
31.1.5.Validate Schema for XDocument