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. 未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage

    本文出处:http://blog.sina.com.cn/s/blog_6fe3efa301016i64.html vs 2005 ,vs 2008, vs 2010,安装后有时出现这个错误(我的机器 ...

  2. C10K 问题引发的技术变革

    C10K 问题引发的技术变革 http://rango.swoole.com/archives/381

  3. Implement Queue using Stacks

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  4. Oracle Coherence应用部署到Jboss EAP 6.x 时 NoClassDefFoundError: sun/rmi/server/MarshalOutputStream 的解决办法

    今天将一个web应用从weblogic 10.3迁移到jboss EAP 6.3上,该应用使用oracle coherence做为缓存,部署上去后,启动时一直报如下错误:     at java.ut ...

  5. es6+react环境搭建

    工具说明 Node Koa React Webpack 项目结构 - build 客户端代码的构建文件目录 - config 项目的配置文件 - docs 项目相关的文档目录 - lib 服务端库文件 ...

  6. 「拉勾网」薪资调查的小爬虫,并将抓取结果保存到excel中

    学习Python也有一段时间了,各种理论知识大体上也算略知一二了,今天就进入实战演练:通过Python来编写一个拉勾网薪资调查的小爬虫. 第一步:分析网站的请求过程 我们在查看拉勾网上的招聘信息的时候 ...

  7. 20151023 - discuz 6 中 insenz 营销推广失效的问题

    将很久之前的论坛重新放在网络上,发现首页打开非常慢,用 Web Inspector 检查,发现 insenz.com 已失效导致. 解决办法: 1.进入数据库:执行 SELECT * FROM cdb ...

  8. 【BZOJ1002】【FJOI2007】轮状病毒(生成树计数)

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1766  Solved: 946[Submit][Status ...

  9. SVN 修改log信息报错的解决方案

    要实现允许修改log这个功能,只需要在hooks目录下增加一个名为:pre-revprop-change.bat的文件,重启svn即可.该文件内容为:------------------------- ...

  10. class文件概述

    将java代码编译后会产生class文件,并且一个clas文件会对应唯一一个java类或者接口.下面对一个通过一个简单的例子来简述一下class文件的结构. java代码 public class J ...