**** Merged from MCS ****
[mono-project.git] / mcs / class / System.XML / Test / System.Xml.Schema / standalone_tests / xs-psci-compare.cs
blob4d91dcdde62478c479a9cdc8a4956227a32db16e
1 using System;
2 using System.Collections;
3 using System.IO;
4 using System.Xml;
5 using System.Xml.Schema;
7 public class Test
9 public static void Main (string [] args)
11 if (args.Length == 0) {
12 Console.WriteLine ("USAGE: xsdump masterlistname");
13 return;
16 try {
17 SchemaDumper.TestDir (args [0], Console.Out);
18 } catch (Exception ex) {
19 Console.WriteLine (ex);
24 public class SchemaDumper
26 public static void TestDir (string masterlist, TextWriter w)
28 FileInfo fi = new FileInfo (masterlist);
29 string dirname = fi.Directory.Parent.FullName;
31 SchemaDumper d = new SchemaDumper (w);
32 #if false
33 foreach (DirectoryInfo di in new DirectoryInfo (dirname).GetDirectories ())
34 foreach (FileInfo fi in di.GetFiles ("*.xsd")) {
35 try {
36 d.IndentLine ("**** File : " + fi.Name);
37 d.DumpSchema (XmlSchema.Read (new XmlTextReader (fi.FullName), null));
38 } catch (Exception ex) {
39 d.IndentLine ("**** Error in " + fi.Name);
42 #else
43 XmlDocument doc = new XmlDocument ();
44 doc.Load (fi.FullName);
46 foreach (XmlElement test in doc.SelectNodes ("/tests/test")) {
47 // Test schema
48 string schemaFile = test.SelectSingleNode ("@schema").InnerText;
49 if (schemaFile.Length > 2)
50 schemaFile = schemaFile.Substring (2);
51 bool isValidSchema = test.SelectSingleNode ("@out_s").InnerText == "1";
53 if (!isValidSchema)
54 continue;
55 #endif
56 try {
57 d.IndentLine ("**** File : " + schemaFile);
58 d.depth++;
59 XmlTextReader xtr = new XmlTextReader (dirname + "/" + schemaFile);
60 d.DumpSchema (XmlSchema.Read (xtr, null));
61 xtr.Close ();
62 } catch (Exception ex) {
63 d.IndentLine ("**** Error in " + schemaFile);
64 } finally {
65 d.depth--;
70 public int depth;
71 TextWriter w;
72 public SchemaDumper (TextWriter w)
74 this.w = w;
77 public void IndentLine (object s)
79 for (int i = 0; i < depth * 2; i++)
80 w.Write (' ');
81 w.WriteLine (s);
84 public void DumpSchema (XmlSchema schema)
86 schema.Compile (null);
88 SortedList sl = new SortedList ();
90 IndentLine ("**XmlSchema**");
91 IndentLine ("TargetNamespace: " + schema.TargetNamespace);
92 IndentLine ("AttributeGroups:");
93 foreach (DictionaryEntry entry in schema.AttributeGroups)
94 sl.Add (entry.Key.ToString (), entry.Value);
95 foreach (DictionaryEntry entry in sl)
96 DumpAttributeGroup ((XmlSchemaAttributeGroup) entry.Value);
97 sl.Clear ();
99 IndentLine ("Attributes:");
100 foreach (DictionaryEntry entry in schema.Attributes)
101 sl.Add (entry.Key.ToString (), entry.Value);
102 foreach (DictionaryEntry entry in sl)
103 DumpAttribute ((XmlSchemaAttribute) entry.Value);
104 sl.Clear ();
106 IndentLine ("Elements:");
107 foreach (DictionaryEntry entry in schema.Elements)
108 sl.Add (entry.Key.ToString (), entry.Value);
109 foreach (DictionaryEntry entry in sl)
110 DumpElement ((XmlSchemaElement) entry.Value);
111 sl.Clear ();
113 IndentLine ("Groups");
114 foreach (DictionaryEntry entry in schema.Groups)
115 sl.Add (entry.Key.ToString (), entry.Value);
116 foreach (DictionaryEntry entry in sl)
117 DumpGroup ((XmlSchemaGroup) entry.Value);
118 sl.Clear ();
120 IndentLine ("IsCompiled: " + schema.IsCompiled);
122 IndentLine ("Notations");
123 foreach (DictionaryEntry entry in schema.Notations)
124 sl.Add (entry.Key.ToString (), entry.Value);
125 foreach (DictionaryEntry entry in sl)
126 DumpNotation ((XmlSchemaNotation) entry.Value);
127 sl.Clear ();
129 IndentLine ("SchemaTypes:");
130 foreach (DictionaryEntry entry in schema.Notations)
131 sl.Add (entry.Key.ToString (), entry.Value);
132 foreach (DictionaryEntry entry in sl)
133 if (entry.Value is XmlSchemaSimpleType)
134 DumpSimpleType ((XmlSchemaSimpleType) entry.Value);
135 else
136 DumpComplexType ((XmlSchemaComplexType) entry.Value);
137 sl.Clear ();
141 public void DumpAttributeGroup (XmlSchemaAttributeGroup ag)
143 depth++;
145 IndentLine ("**AttributeGroup**");
146 IndentLine ("Name = " + ag.Name);
147 if (ag.RedefinedAttributeGroup != null) {
148 IndentLine ("RedefinedGroup:");
149 DumpAttributeGroup (ag.RedefinedAttributeGroup);
152 depth--;
155 public void DumpAttribute (XmlSchemaAttribute a)
157 depth++;
159 IndentLine ("**Attribute**");
160 IndentLine ("QualifiedName: " + a.QualifiedName);
161 IndentLine ("RefName: " + a.RefName);
162 IndentLine ("AttributeType:");
163 DumpType (a.AttributeType);
165 depth--;
168 public void DumpElement (XmlSchemaElement e)
170 depth++;
172 IndentLine ("**Element**");
173 IndentLine ("QualifiedName: " + e.QualifiedName);
174 IndentLine ("ElementType:");
175 DumpType (e.ElementType);
177 depth--;
180 public void DumpGroup (XmlSchemaGroup g)
182 depth++;
184 IndentLine ("**Group**");
185 IndentLine ("Name: " + g.Name);
187 depth--;
190 public void DumpNotation (XmlSchemaNotation n)
192 depth++;
194 IndentLine ("**Notation**");
195 IndentLine ("Name: " + n.Name);
198 depth--;
201 public void DumpType (object type)
203 depth++;
205 if (type is XmlSchemaComplexType)
206 DumpComplexType ((XmlSchemaComplexType) type);
207 else if (type is XmlSchemaSimpleType)
208 DumpSimpleType ((XmlSchemaSimpleType) type);
209 else if (type is XmlSchemaDatatype)
210 DumpDatatype ((XmlSchemaDatatype) type);
211 else
212 IndentLine ("Unexpected Type: " + type);
214 depth--;
217 public void DumpSimpleType (XmlSchemaSimpleType s)
219 depth++;
221 IndentLine ("**SimpleType**");
222 IndentLine ("QualifiedName: " + s.QualifiedName);
223 IndentLine ("BaseSchemaType:");
224 DumpType (s.BaseSchemaType);
226 depth--;
229 public void DumpComplexType (XmlSchemaComplexType c)
231 depth++;
233 IndentLine ("**ComplexType**");
234 IndentLine ("QualifiedName: " + c.QualifiedName);
235 IndentLine ("ContentType: " + c.ContentType);
236 IndentLine ("ContentTypeParticle: ");
237 DumpParticle (c.ContentTypeParticle);
238 IndentLine ("BaseSchemaType:");
239 DumpType (c.BaseSchemaType);
241 depth--;
244 public void DumpParticle (XmlSchemaParticle p)
246 if (p is XmlSchemaGroupBase)
247 DumpGroupBase ((XmlSchemaGroupBase) p);
248 else if (p is XmlSchemaElement)
249 DumpElementNoRecurse ((XmlSchemaElement) p);
250 else if (p is XmlSchemaAny)
251 DumpAny ((XmlSchemaAny) p);
252 else
253 IndentLine (p);
256 public void DumpDatatype (XmlSchemaDatatype d)
258 depth++;
260 IndentLine ("**Datatype**");
261 IndentLine ("TokenizedType: " + d.TokenizedType);
262 IndentLine ("ValueType: " + d.ValueType);
264 depth--;
267 public void DumpGroupBase (XmlSchemaGroupBase gb)
269 depth++;
271 IndentLine ("**GroupBase**");
272 IndentLine ("Type: " + gb);
273 IndentLine ("MinOccurs: " + gb.MinOccurs);
274 IndentLine ("MaxOccurs: " + gb.MaxOccurs);
275 IndentLine ("Items: ");
276 foreach (XmlSchemaParticle p in gb.Items)
277 DumpParticle (p);
279 depth--;
282 public void DumpElementNoRecurse (XmlSchemaElement e)
284 depth++;
286 IndentLine ("**Element**");
287 IndentLine ("QualifiedName: " + e.QualifiedName);
289 depth--;
292 public void DumpAny (XmlSchemaAny any)
294 depth++;
296 IndentLine ("**Any**");
297 // IndentLine ("Namespace: " + any.Namespace);
299 depth--;