* Initial checkin. docval is a validation tool for monodoc xml.
[mono.git] / mcs / doctools / src / Console / docval.cs
1 //      docval.cs
2 //
3 //      Adam Treat (manyoso@yahoo.com)
4 //      (C) 2002 Adam Treat
5 //
6 //      This program is free software; you can redistribute it and/or modify
7 //      it under the terms of the GNU General Public License as published by
8 //      the Free Software Foundation; either version 2 of the License, or
9 //      (at your option) any later version.
10
11 using System;
12 using System.Xml;
13
14 namespace Mono.Util {
15
16         class DocVal {
17
18                 string file;
19
20                 void Usage()
21                 {
22                         Console.Write ("docval [file]\n\n");
23                 }
24
25                 public static void Main(string[] args)
26                 {
27                         DocVal val = new DocVal(args);
28                 }
29
30                 public DocVal(string [] args)
31                 {
32                         bool pass = true;
33                         file = null;
34                         int argc = args.Length;
35
36                         for(int i = 0; i < argc; i++) {
37                                 string arg = args[i];
38                                 if(arg.EndsWith(".xml")) {
39                                         file = arg;
40                                 }
41                         }
42
43                         if(file == null) {
44                                 Usage();
45                                 return;
46                         }
47
48                         try {
49                                 XmlTextReader read = new XmlTextReader(file);
50                                 XmlValidatingReader validate = new XmlValidatingReader(read);
51                                 validate.ValidationType = ValidationType.Auto;
52                                 while (validate.Read()) {
53                                         switch (validate.NodeType) {
54                                                 case XmlNodeType.XmlDeclaration:
55                                                         Console.WriteLine("** XML declaration");
56                                                         break;
57                                                 case XmlNodeType.DocumentType:
58                                                         Console.WriteLine("** DocumentType node");
59                                                         break;
60                                                 case XmlNodeType.Document:
61                                                         Console.WriteLine("** Document node");
62                                                         break;
63                                                 case XmlNodeType.Element:
64                                                         Console.WriteLine("** Element: {0}", validate.Name);
65                                                 break;
66                                                 case XmlNodeType.EndElement:
67                                                         Console.WriteLine("** End Element: {0}", validate.Name);
68                                                         break;
69                                                 case XmlNodeType.Text:
70                                                         Console.WriteLine("** Text: {0}", validate.Value);
71                                                         break;
72                                                 case XmlNodeType.Comment:
73                                                         Console.WriteLine("** Comment: {1}", validate.Name, validate.Value);
74                                                         break;
75                                                 case XmlNodeType.Whitespace:
76                                                         break;
77                                                 default:
78                                                         pass = false;
79                                                         Console.WriteLine("** ERROR: Unknown node type");
80                                                         break;
81                                         }
82                                 }
83                         } catch (Exception e) {
84                                 pass = false;
85                                 Console.WriteLine(e);
86                         }
87                         if(pass) {
88                                 Console.Write("\n   Validation: PASSED!\n\n");
89                         } else {
90                                 Console.Write("\n   Validation: FAILED!\n\n");
91                         }
92                 }
93         }
94 }