zoukankan      html  css  js  c++  java
  • 根据xsd生成C#类

    var file = "1.xsd";
        
                // Get the namespace for the schema.
                CodeNamespace ns = Processor.Process(file, "Dm");
                // Create the appropriate generator for the language.
                CodeDomProvider provider;
                if ("cs" == "cs")
                    provider = new Microsoft.CSharp.CSharpCodeProvider();
                else if (args[3] == "vb")
                    provider = new Microsoft.VisualBasic.VBCodeProvider();
                else
                    throw new ArgumentException("Invalid language", args[3]);
                // Write the code to the output file.
                using (StreamWriter sw = new StreamWriter(file, false))
                {
                    provider.CreateGenerator().GenerateCodeFromNamespace(
                      ns, sw, new CodeGeneratorOptions());
                }
                Console.WriteLine("Finished");
                Console.Read();

    Process

    public sealed class Processor
            {
                public static CodeNamespace Process(string xsdFile,
                   string targetNamespace)
                {
                    // Load the XmlSchema and its collection. 
                    XmlSchema xsd;
                    using (FileStream fs = new FileStream(xsdFile, FileMode.Open))
                    {
                        xsd = XmlSchema.Read(fs, null);
                        xsd.Compile(null);
                    }
                    XmlSchemas schemas = new XmlSchemas();
                    schemas.Add(xsd);
                    // Create the importer for these schemas. 
                    XmlSchemaImporter importer = new XmlSchemaImporter(schemas);
                    // System.CodeDom namespace for the XmlCodeExporter to put classes in. 
                    CodeNamespace ns = new CodeNamespace(targetNamespace);
                    XmlCodeExporter exporter = new XmlCodeExporter(ns);
                    // Iterate schema top-level elements and export code for each. 
                    foreach (XmlSchemaElement element in xsd.Elements.Values)
                    {
                        // Import the mapping first. 
                        XmlTypeMapping mapping = importer.ImportTypeMapping(
                          element.QualifiedName);
                        // Export the code finally. 
                        exporter.ExportTypeMapping(mapping);
                    }
                    return ns;
                }
            } 

    Client

  • 相关阅读:
    canvas,画个纸飞机
    时钟
    去除滚动条,内容仍然可以滚动
    鼠标指针移入移出改变图片透明度
    Mysql数据库优化总结
    一次利用nginx漏洞的木马事件
    一个批量删除大表数据的shell小脚本
    MegaCli监控raid卡磁盘信息以及相关的shell脚本
    MYSQL delete语句不支持别名?
    一次Mysql数据库服务器磁盘空间满引发的写入和同步问题
  • 原文地址:https://www.cnblogs.com/damsoft/p/6042457.html
Copyright © 2011-2022 走看看