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[] == "vb")
provider = new Microsoft.VisualBasic.VBCodeProvider();
else
throw new ArgumentException("Invalid language", args[]);
// 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

根据xsd生成C#类的更多相关文章

  1. 通过xsd生成xml类

    步骤二:使用VS2010 Tools中的命令提示窗口 如下图所示 执行结果:生成myschema.xsd对应的C#类文件. 命令剖析: /c  生成对应的类文件 /l:cs 类文件使用C#语言 /ou ...

  2. 使用jaxb用xsd生成java类

    命令: xjc -p 包的路径 xsd的名字.xsd -d 目标的文件夹 具体详细见: http://www.iteye.com/topic/1118082

  3. xsd、wsdl生成C#类的命令行工具使用方法

    1.xsd生成C#类命令 示例:xsd <xsd文件路径> /c /o:<生成CS文件目录> <其他参数> 参数说明: /c 生成为cs文件,/d 生成DataSe ...

  4. Hibernate、Mybatis 通过数据库表反向生成java类和配置

    一.通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件    (转载孙宇老师的文章) 二.Mybatis生成实体类和配置文件: myeclipse下生 ...

  5. xsd转实体类

    话说VS自带的工具,可以将xsd或者xml格式的文件转成实体类,大概格式如下 使用VS2005工具XSD.exe(SDK/v2.0/Bin/xsd.exe)自动生成实体类: xsd /c /names ...

  6. Mybatis自动生成实体类

    Maven自动生成实体类需要的jar包 一.pom.xml中 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  7. Springboot mybatis generate 自动生成实体类和Mapper

    https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...

  8. maven 工程mybatis自动生成实体类

    generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ge ...

  9. 按WSDL信息手动生成代理类

    命令行: wsdl /language:c# /n:Entity /out:C:\Users\mengxianming\Desktop\Centrex_IMS_Client.cs C:\Users\m ...

随机推荐

  1. 解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题

    下面两种现象,用同一种方法解决 1.解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题 2.突然有一天首页访问图片很慢,至少隔20多秒所有图片才会出来.(解析:app使 ...

  2. vs 2005 thread 无法调试

    两种办法:1.打开项目属性,在“Debug”一项里,把“Enable the Visual Studio hosting process”前的钩去掉.这个方法不是好办法.2.打开计算机管理,在服务里将 ...

  3. MVC3中常用的一些控件及方法

    1.返回提示框 string script = String.Format("<script>alert('登录状态已失效! 请重新登录系统');location.href='{ ...

  4. H2 Database入门

    H2 Database做为轻量级的内嵌数据库,功能十分强大,而且运行时只需要一个jar包即可,下表是官网的描述: 更详细的对比见官网页面: http://www.h2database.com/html ...

  5. Python 操作 MongoDB

    原文 这篇文章主要介绍了使用Python脚本操作MongoDB的教程,MongoDB作为非关系型数据库得到了很大的宣传力度,而市面上的教程一般都是讲解JavaScript的脚本操作,本文则是基于Pyt ...

  6. Java7并发编程实战(一) 线程的管理

    1:线程的创建   1:继承Thread类,并且覆盖run()方法  2:创建一个实现Runnable接口的类.使用带参数的Thread构造器来构造 2:example-->计算打印乘法表 首先 ...

  7. linux的一些常用命令

    这几天正好在研究linux系统,打算将下一个项目部署在linux系统的服务器上已提高安全性(被window 2003已经折磨的不行了),经过各方了解和深思熟虑后决定使用linux系统的CentOs版本 ...

  8. C# 传值给C++

    http://www.cnblogs.com/xumingming/archive/2008/10/10/1308248.html C#(.net)中的DllImport    大家在实际工作学习C# ...

  9. Middleware的艺术

    定义 Middleware直译叫中间件,目前在百度上很难找到一个简单明了的含义解释,.Net下以前也比较难以看到它的身影,但在Microsoft.Owin里,多个地方都看到MiddleWare,我近来 ...

  10. canvas 2d 贴图技术实践

    最近在公司内部的技术协会论坛里闲逛的时候,无意中发现了一篇手淘前端大牛岑安两年前写的博文,讲述了canvas的2d贴图技术.看到后觉得相当神奇.于是就自己实现了一下.不过岑安前辈的那篇博文也只是大概讲 ...