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