根据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 ...
随机推荐
- Java集合系列:-----------08HashMap的底层实现
对于HashMap感觉一直是看了忘,忘了看.这里就单独写一篇日志来记录一下.HashMap的底层实现. 非常好的讲HashMap的博客:http://blog.csdn.net/vking_wang/ ...
- Alwayson--SYS.dm_hadr_instance_node_map 返回0行
下面是MSDN关于SYS.dm_hadr_instance_node_map 的解释,我就不在翻译了 For every instance of SQL Server that hosts an av ...
- (原创)解决远程桌面连接远程应用时,出现 '应用程序错误: '0x7c931780'指令引用的 '0x89abcdef' 内存。该内存不能为 'read'"
公司的部分应用为cs结构,没有web版的,这些应用的外部访问基本都是通过使用windows server 2008 r2的远程桌面服务来实现的. 个人感觉微软远程桌面服务问题很多,今天有同事使用Rem ...
- iis7 运行 php5.5 的方法
首先添加IIS. 控制面板-〉程序-〉打开或关闭Windows功能 1. 勾选“Internet 信息服务” 2. 勾选“IIS 管理控制台” Internet 信息服务-〉Web 管理工具 ...
- flask+sqlite3+echarts2+ajax数据可视化--静态图
结构: /www | |-- /static | | | |-- echarts.js(当然还有echarts原dist目录下的文件(夹)) | |-- /templates | | | |-- in ...
- TinyFrame升级之一:框架概览
由于之前的TinyFrame多于简单,并且只是说明原理,并无成型的框架出来,所以这次我把之前的知识进行了汇总,然后做出了这一版的TinyFrame框架. 整个框架的结构如下: TinyFrame.Da ...
- Oracle 常用操作【01】修改、更新数据
1. oracle 修改表名.列名.字段类型.添加表列.删除表列 alert table scott.test rename to test1--修改表名 alter table scott.tes ...
- PHP 对于 MYSQL 基础操作
基础 <?php // 不打印 notice info // error_reporting(0); // 连接 mysql $con = mysql_connect("localho ...
- 我的开发框架之ORM框架
今天我想分享一下我自己的ORM框架,虽然谈不是很好,但我个人认为还是蛮好用的,跟大家分享交流一下. 首先说说我对现在主流的ORM框架的一些看法: 优点: 让程序员不再关注数据库细节,专心在业务逻辑上, ...
- 3DMax 物体选择方法
全选: Ctrl + A, 取消选择:Ctrl +D 加选:ctrl+鼠标左键:减选:alt+鼠标 窗口与交叉:下面红框内的右边的按钮, 是切换两种模式: 选择模式一:只要选框碰到物体边缘, 就可选中 ...