2 using System.Collections.Generic;
4 using System.Reflection;
6 using System.Xml.Schema;
8 namespace Mono.Documentation
10 public class MDocValidator
12 static XmlValidatingReader reader;
13 static XmlSchema schema;
14 static long errors = 0;
15 static bool IsValid = true;
17 public static void Run (string format, IEnumerable<string> files)
23 s = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("monodoc-ecma.xsd");
27 throw new NotSupportedException (string.Format ("The format `{0}' is not suppoted.", format));
31 throw new NotSupportedException (string.Format ("The schema for `{0}' was not found.", format));
33 schema = XmlSchema.Read (s, null);
34 schema.Compile (null);
36 // skip args[0] because it is the provider name
37 foreach (string arg in files) {
38 if (IsMonodocFile (arg))
41 if (Directory.Exists (arg))
43 RecurseDirectory (arg);
47 Console.WriteLine ("Total validation errors: {0}", errors);
50 static void ValidateFile (string file)
54 reader = new XmlValidatingReader (new XmlTextReader (file));
55 reader.ValidationType = ValidationType.Schema;
56 reader.Schemas.Add (schema);
57 reader.ValidationEventHandler += new ValidationEventHandler (OnValidationEvent);
58 while (reader.Read ()) {
64 Console.WriteLine ("mdvalidator: error: " + e.ToString ());
68 static void RecurseDirectory (string dir)
70 string[] files = Directory.GetFiles (dir, "*.xml");
71 foreach (string f in files)
73 if (IsMonodocFile (f))
77 string[] dirs = Directory.GetDirectories (dir);
78 foreach (string d in dirs)
82 static void OnValidationEvent (object sender, ValidationEventArgs a)
87 Console.WriteLine (a.Message);
90 static bool IsMonodocFile (string file)
92 if (File.Exists (file) && Path.GetExtension (file).ToLower () == ".xml")