Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // download and unzip http://docs.oasis-open.org/ubl/os-UBL-2.1/UBL-2.1.zip
            string ublBasePath = "C:/Users/johan/Documents/ubl/UBL-2.1/xsd";

            XmlNameTable nt        = new NameTable();
            XmlSchemaSet schemaSet = new XmlSchemaSet(nt);

            schemaSet.ValidationEventHandler += MaindocSchemaSet_ValidationEventHandler;
            schemaSet.AddFilesFromDirectory(ublBasePath, MaindocSchemaSet_ValidationEventHandler);
            Console.WriteLine("Files not parsed:");
            schemaSet.GetFilesNotLoaded(ublBasePath).ForEach(Console.WriteLine);

            Console.WriteLine("Compiling ...");
            schemaSet.Compile();

            // show namespaces and prefix
            // schemaSet.GetNamespacePrefixes().ToList().ForEach(ns => Console.WriteLine($"{ns.Name}\t {ns.Namespace}"));

            var commonProps = schemaSet.MaindocCommonElements();

            foreach (var item in commonProps)
            {
                Console.WriteLine(item.QualifiedName.Name);
            }

            schemaSet.MaindocCommonElements();

            using (var writer = File.CreateText("result.txt"))
            {
                int len = schemaSet.Schemas().Cast <XmlSchema>().First().SourceUri.IndexOf("/xsd/") + 5;
                foreach (XmlSchema schema in schemaSet.Schemas())
                {
                    string s = $"{schema.SourceUri.Remove(0, len)}\t {schema.TargetNamespace}";
                    writer.WriteLine(s);
                }
                writer.WriteLine(Environment.NewLine + "Common properties:");
                foreach (var p in commonProps)
                {
                    writer.WriteLine(p.QualifiedName.Name);
                }
            }
        }