2 using System.Collections;
5 using System.Xml.Schema;
9 public static void Main (string [] args)
11 if (args.Length == 0) {
12 Console.WriteLine ("USAGE: xsdump masterlistname");
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);
33 foreach (DirectoryInfo di in new DirectoryInfo (dirname).GetDirectories ())
34 foreach (FileInfo fi in di.GetFiles ("*.xsd")) {
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);
43 XmlDocument doc = new XmlDocument ();
44 doc.Load (fi.FullName);
46 foreach (XmlElement test in doc.SelectNodes ("/tests/test")) {
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";
57 d.IndentLine ("**** File : " + schemaFile);
59 XmlTextReader xtr = new XmlTextReader (dirname + "/" + schemaFile);
60 d.DumpSchema (XmlSchema.Read (xtr, null));
62 } catch (Exception ex) {
63 d.IndentLine ("**** Error in " + schemaFile);
72 public SchemaDumper (TextWriter w)
77 public void IndentLine (object s)
79 for (int i = 0; i < depth * 2; i++)
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);
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);
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);
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);
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);
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);
136 DumpComplexType ((XmlSchemaComplexType) entry.Value);
141 public void DumpAttributeGroup (XmlSchemaAttributeGroup ag)
145 IndentLine ("**AttributeGroup**");
146 IndentLine ("Name = " + ag.Name);
147 if (ag.RedefinedAttributeGroup != null) {
148 IndentLine ("RedefinedGroup:");
149 DumpAttributeGroup (ag.RedefinedAttributeGroup);
155 public void DumpAttribute (XmlSchemaAttribute a)
159 IndentLine ("**Attribute**");
160 IndentLine ("QualifiedName: " + a.QualifiedName);
161 IndentLine ("RefName: " + a.RefName);
162 IndentLine ("AttributeType:");
163 DumpType (a.AttributeType);
168 public void DumpElement (XmlSchemaElement e)
172 IndentLine ("**Element**");
173 IndentLine ("QualifiedName: " + e.QualifiedName);
174 IndentLine ("ElementType:");
175 DumpType (e.ElementType);
180 public void DumpGroup (XmlSchemaGroup g)
184 IndentLine ("**Group**");
185 IndentLine ("Name: " + g.Name);
190 public void DumpNotation (XmlSchemaNotation n)
194 IndentLine ("**Notation**");
195 IndentLine ("Name: " + n.Name);
201 public void DumpType (object type)
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);
212 IndentLine ("Unexpected Type: " + type);
217 public void DumpSimpleType (XmlSchemaSimpleType s)
221 IndentLine ("**SimpleType**");
222 IndentLine ("QualifiedName: " + s.QualifiedName);
223 IndentLine ("BaseSchemaType:");
224 DumpType (s.BaseSchemaType);
229 public void DumpComplexType (XmlSchemaComplexType c)
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);
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);
256 public void DumpDatatype (XmlSchemaDatatype d)
260 IndentLine ("**Datatype**");
261 IndentLine ("TokenizedType: " + d.TokenizedType);
262 IndentLine ("ValueType: " + d.ValueType);
267 public void DumpGroupBase (XmlSchemaGroupBase gb)
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)
282 public void DumpElementNoRecurse (XmlSchemaElement e)
286 IndentLine ("**Element**");
287 IndentLine ("QualifiedName: " + e.QualifiedName);
292 public void DumpAny (XmlSchemaAny any)
296 IndentLine ("**Any**");
297 // IndentLine ("Namespace: " + any.Namespace);