using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Xml;
{
public class MDocValidator : MDocCommand
{
- static XmlValidatingReader reader;
- static XmlSchema schema;
- static long errors = 0;
- static bool IsValid = true;
+ XmlReaderSettings settings;
+ long errors = 0;
public override void Run (IEnumerable<string> args)
{
"ecma",
};
string format = "ecma";
- bool showHelp = false;
var p = new OptionSet () {
{ "f|format=",
"The documentation {0:FORMAT} used within PATHS. " +
Run (format, files);
}
- public static void Run (string format, IEnumerable<string> files)
+ public void Run (string format, IEnumerable<string> files)
{
Stream s = null;
if (s == null)
throw new NotSupportedException (string.Format ("The schema for `{0}' was not found.", format));
- schema = XmlSchema.Read (s, null);
- schema.Compile (null);
+ settings = new XmlReaderSettings ();
+ settings.Schemas.Add (XmlSchema.Read (s, null));
+ settings.Schemas.Compile ();
+ settings.ValidationType = ValidationType.Schema;
+ settings.ValidationEventHandler += OnValidationEvent;
// skip args[0] because it is the provider name
foreach (string arg in files) {
}
}
- Console.WriteLine ("Total validation errors: {0}", errors);
+ Message (errors == 0 ? TraceLevel.Info : TraceLevel.Error,
+ "Total validation errors: {0}", errors);
}
- static void ValidateFile (string file)
+ void ValidateFile (string file)
{
- IsValid = true;
try {
- reader = new XmlValidatingReader (new XmlTextReader (file));
- reader.ValidationType = ValidationType.Schema;
- reader.Schemas.Add (schema);
- reader.ValidationEventHandler += new ValidationEventHandler (OnValidationEvent);
- while (reader.Read ()) {
- // do nothing
+ using (var reader = XmlReader.Create (new XmlTextReader (file), settings)) {
+ while (reader.Read ()) {
+ // do nothing
+ }
}
- reader.Close ();
}
catch (Exception e) {
- Console.WriteLine ("mdvalidator: error: " + e.ToString ());
+ Message (TraceLevel.Error, "mdoc: {0}", e.ToString ());
}
}
- static void RecurseDirectory (string dir)
+ void RecurseDirectory (string dir)
{
string[] files = Directory.GetFiles (dir, "*.xml");
foreach (string f in files)
RecurseDirectory (d);
}
- static void OnValidationEvent (object sender, ValidationEventArgs a)
+ void OnValidationEvent (object sender, ValidationEventArgs a)
{
- if (IsValid)
- IsValid = false;
errors ++;
- Console.WriteLine (a.Message);
+ Message (TraceLevel.Error, "mdoc: {0}", a.Message);
}
static bool IsMonodocFile (string file)
-XmlSchema error: Invalid start element: :extra XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
-XmlSchema error: Element declaration for extra is missing. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
-XmlSchema error: Invalid end element: Docs XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 21, Position 5.
+mdoc: XmlSchema error: Invalid start element: :extra XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
+mdoc: XmlSchema error: Element declaration for extra is missing. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
+mdoc: XmlSchema error: Invalid end element. There are still required content items. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 21, Position 5.
Total validation errors: 3