using Microsoft.CSharp; using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections; using System.IO; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; public class Test { public static void Main (string [] args) { if (args.Length == 0) { Console.WriteLine ("USAGE: xsdump masterlistname"); return; } try { SchemaImportTester.TestDir (args [0], Console.Out); } catch (Exception ex) { Console.WriteLine (ex); } } } public class SchemaImportTester { public static void TestDir (string masterlist, TextWriter w) { FileInfo fi = new FileInfo (masterlist); string dirname = fi.Directory.Parent.FullName; SchemaImportTester d = new SchemaImportTester (w); XmlDocument doc = new XmlDocument (); doc.Load (fi.FullName); ICodeGenerator gen = new CSharpCodeProvider ().CreateGenerator (); foreach (XmlElement test in doc.SelectNodes ("/tests/test")) { // Test schema string schemaFile = test.SelectSingleNode ("@schema").InnerText; if (schemaFile.Length > 2) schemaFile = schemaFile.Substring (2); bool isValidSchema = test.SelectSingleNode ("@out_s").InnerText == "1"; if (!isValidSchema) continue; // (MS) Error cases are listed here: if (schemaFile.IndexOf ("attZ001") >= 0) continue; if (schemaFile.IndexOf ("idF025") >= 0) continue; if (schemaFile.IndexOf ("idF030") >= 0) continue; if (schemaFile.IndexOf ("idF034") >= 0) continue; if (schemaFile.IndexOf ("idG019") >= 0) continue; if (schemaFile.IndexOf ("idG024") >= 0) continue; if (schemaFile.IndexOf ("idG028") >= 0) continue; if (schemaFile.IndexOf ("idH023") >= 0) continue; if (schemaFile.IndexOf ("idH028") >= 0) continue; if (schemaFile.IndexOf ("idH032") >= 0) continue; // (Mono) Error cases are listed here: if (schemaFile.IndexOf ("attgC006") >= 0) continue; if (schemaFile.IndexOf ("attgC007") >= 0) continue; if (schemaFile.IndexOf ("attgC034") >= 0) continue; if (schemaFile.IndexOf ("attgC036") >= 0) continue; if (schemaFile.IndexOf ("attgC037") >= 0) continue; if (schemaFile.IndexOf ("attgC038") >= 0) continue; if (schemaFile.IndexOf ("attgC041") >= 0) continue; if (schemaFile.IndexOf ("attgC043") >= 0) continue; if (schemaFile.IndexOf ("attgC045") >= 0) continue; if (schemaFile.IndexOf ("attgD035") >= 0) continue; if (schemaFile.IndexOf ("attgD036") >= 0) continue; try { w.WriteLine ("**** File : " + schemaFile); d.depth++; XmlTextReader xtr = new XmlTextReader (dirname + "/" + schemaFile); d.TestSchema (gen, XmlSchema.Read (xtr, null)); xtr.Close (); } catch (Exception ex) { w.WriteLine ("**** Error in " + schemaFile); } finally { d.depth--; } } } public int depth; TextWriter w; public SchemaImportTester (TextWriter w) { this.w = w; } public void TestSchema (ICodeGenerator gen, XmlSchema schema) { schema.Compile (null); XmlSchemas schemas = new XmlSchemas (); schemas.Add (schema); CodeCompileUnit ccu = new CodeCompileUnit (); CodeNamespace cns = new CodeNamespace (); ccu.Namespaces.Add (cns); XmlCodeExporter exp = new XmlCodeExporter (cns, ccu); XmlSchemaImporter imp = new XmlSchemaImporter (schemas); foreach (DictionaryEntry entry in schema.Elements) { XmlTypeMapping map = imp.ImportTypeMapping (entry.Key as XmlQualifiedName); exp.ExportTypeMapping (map); } gen.GenerateCodeFromCompileUnit (ccu, w, null); } }