根据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[] == "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#类的更多相关文章
- 通过xsd生成xml类
步骤二:使用VS2010 Tools中的命令提示窗口 如下图所示 执行结果:生成myschema.xsd对应的C#类文件. 命令剖析: /c 生成对应的类文件 /l:cs 类文件使用C#语言 /ou ...
- 使用jaxb用xsd生成java类
命令: xjc -p 包的路径 xsd的名字.xsd -d 目标的文件夹 具体详细见: http://www.iteye.com/topic/1118082
- xsd、wsdl生成C#类的命令行工具使用方法
1.xsd生成C#类命令 示例:xsd <xsd文件路径> /c /o:<生成CS文件目录> <其他参数> 参数说明: /c 生成为cs文件,/d 生成DataSe ...
- Hibernate、Mybatis 通过数据库表反向生成java类和配置
一.通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件 (转载孙宇老师的文章) 二.Mybatis生成实体类和配置文件: myeclipse下生 ...
- xsd转实体类
话说VS自带的工具,可以将xsd或者xml格式的文件转成实体类,大概格式如下 使用VS2005工具XSD.exe(SDK/v2.0/Bin/xsd.exe)自动生成实体类: xsd /c /names ...
- Mybatis自动生成实体类
Maven自动生成实体类需要的jar包 一.pom.xml中 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
- Springboot mybatis generate 自动生成实体类和Mapper
https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...
- maven 工程mybatis自动生成实体类
generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ge ...
- 按WSDL信息手动生成代理类
命令行: wsdl /language:c# /n:Entity /out:C:\Users\mengxianming\Desktop\Centrex_IMS_Client.cs C:\Users\m ...
随机推荐
- BZOJ 4034 【HAOI2015】 T2
Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中所 ...
- 安装 SQL SERVER 2008 必须使用 "角色管理工具" 错误 的 解决方案 (转)
刚在服务器(Win2008)上安装SqlServer2008的时候出现了这么一个报错——必须使用“角色管理工具”安装或配置Microsoft .NET Framework 3.5 SP1.一开始以为是 ...
- 在 C# App 中嵌入 Chrome 浏览器使用 CefSharp
介绍 以前曾试过在app中整合一个可靠又快速的web浏览器吗? 在本文中,你会学到如何轻松地将奇妙的CefSharp网页浏览器组件(基于Chromium)集成到你的C# app中. 然后,你可以使用此 ...
- SQL Server 用SSMS查看依赖关系有时候不准确,改用代码查
SQL Server 用SSMS查看依赖关系有时候不准确,明明某个sp中有用到表tohen,查看表tohen的依赖关系的时候,却看不到这个sp 用代码查看方式如下: --依赖于表tohen的对象 SE ...
- &11,散列表
#1,是什么? 散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个 ...
- 扩展 easyui-tabs 插件 关闭标签页方法
$.extend($.fn.tabs.methods,{ allTabs:function(jq){ var tabs = $(jq).tabs('tabs'); var all = []; all ...
- 数据字典生成工具之旅(6):NVelocity语法介绍及实例
本章开始将会为大家讲解NVelocity的用法,并带领大家实现一个简单的代码生成器. NVelocity是一个基于.NET的模板引擎(template engine).它允许任何人仅仅简单的使用模板语 ...
- c++ 副本构造器
我们都知道两个指针指向同一个变量时如果一个指针被释放那么另一个就会出问题 为了说明问题我做了一个很恶心的小例子 class C { public : C(int v) { ptrInt=new int ...
- C/C++实践笔记 003
数据结构与算法程序=数据结构+算法语言是一种工具语言工具(c,c++)--程序设计方法(面向过程.面向对象)——数据结构(二叉树.队列.栈.红黑树.链表……)——算法(快速排序算法.冒泡排序算法.选择 ...
- IOS自学
初识IOS 开发工具:xcode , 第一步学习c 打开xcode 新建一个object #include<stdio.h>//引入一个库,支持pringf输出功能 /* this is ...