XmlSchemaObject represents the root class for the Xml schema
using System; using System.Xml; using System.Xml.Schema; using System.IO; using System.Reflection; public class ValidXSD { public static int Main() { string xsd = "example.xsd"; FileStream fs; XmlSchema schema; fs = new FileStream(xsd, FileMode.Open); schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError)); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ShowCompileError); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } schema = compiledSchema; if (schema.IsCompiled) { DisplayObjects(schema); } return 0; } private static void DisplayObjects(object o) { foreach (PropertyInfo property in o.GetType().GetProperties()) { if (property.PropertyType.FullName == "System.Xml.Schema.XmlSchemaObjectCollection") { XmlSchemaObjectCollection childObjectCollection = (XmlSchemaObjectCollection)property.GetValue(o, null); foreach (XmlSchemaObject schemaObject in childObjectCollection) { DisplayObjects(schemaObject); } } } } private static void ShowCompileError(object sender, ValidationEventArgs e) { Console.WriteLine("Validation Error: {0}", e.Message); } }