C# xsd转C#类(转)

 

第一次听leader说可以直接将xsd转化为类,查了一下xsd命令:

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.

xsd.exe -
    Utility to generate schema or class files from given source.

xsd.exe <schema>.xsd /classes|dataset [/e:] [/l:] [/n:] [/o:] [/s] [/uri:]
xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]
xsd.exe <instance>.xml [/outputdir:]
xsd.exe <schema>.xdr [/outputdir:]

     - OPTIONS -

/classes
    Generate classes for this schema. Short form is '/c'.

/dataset
    Generate sub-classed DataSet for this schema. Short form is '/d'.

/enableLinqDataSet
    Generate LINQ-enabled sub-classed Dataset for the schemas provided.  Short f
orm is '/eld'.

/element:<element>
    Element from schema to process. Short form is '/e:'.

/fields
    Generate fields instead of properties. Short form is '/f'.

/order
    Generate explicit order identifiers on all particle members.

/enableDataBinding
    Implement INotifyPropertyChanged interface on all generated types
    to enable data binding. Short form is '/edb'.

/language:<language>
    The language to use for the generated code. Choose from 'CS', 'VB', 'JS',
    'VJS', 'CPP' or provide a fully-qualified name for a class implementing
    System.CodeDom.Compiler.CodeDomProvider. The default language
    is 'CS' (CSharp). Short form is '/l:'.

/namespace:<namespace>
    The namespace for generated class files. The default namespace
    is the global namespace. Short form is '/n:'.

/nologo
    Suppresses the banner.

/out:<directoryName>
    The output directory to create files in. The default
    is the current directory. Short form is '/o:'.

/type:<type>
    Type from assembly to generate schema for. Multiple types may be provided.
    If no types are provided, then schemas for all types in an assembly
    are generated. Short form is '/t:'.

/uri:<uri>
    Uri of elements from schema to process. Short form is '/u:'.

     - ADVANCED -

/parameters:<file>
    Read command-line options from the specified xml file. Short form is '/p:'.

     - ARGUMENTS -
<schema>.xsd       Name of a schema containing elements to import.
<assembly>.dll|exe Name of an assembly containing types to generate schema for.
<instance>.xml     Name of an xml file to infer xsd schema from.
<schema>.xdr       Name of an xdr schema to convert to xsd.
Multiple file arguments of the same type may be provided.

 

常用格式 xsd /c + xsd文件名 + /l: + 语言(默认C#)+ /o: + 输出路径

转载于:https://www.cnblogs.com/xmyy/archive/2012/12/27/2835440.html

根据提供的引用内容,我无法确定您需要了解关于C# xsd XmlSchemaKey的哪方面知识。但是,我可以为您提供有关XmlSchemaKey的一些基本信息。 XmlSchemaKey是XmlSchema中的一个,它表示XML架构中的键约束。键约束用于确保XML文档中的元素具有唯一的标识符。XmlSchemaKey定义了以下属性和方法: - Name:获取或设置XmlSchemaKey的名称。 - Selector:获取或设置用于选择要应用键约束的元素的XPath表达式。 - Fields:获取XmlSchemaKey的XmlSchemaObjectCollection,该集合包含用于定义键字段的XmlSchemaXPath的实例。 以下是一个示例,演示如何在C#中使用XmlSchemaKey: ```csharp using System; using System.Xml; using System.Xml.Schema; class Program { static void Main(string[] args) { // 创建一个XmlSchema对象 XmlSchema schema = new XmlSchema(); // 创建一个XmlSchemaElement对象 XmlSchemaElement element = new XmlSchemaElement(); element.Name = "book"; schema.Items.Add(element); // 创建一个XmlSchemaComplexType对象 XmlSchemaComplexType complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; // 创建一个XmlSchemaSequence对象 XmlSchemaSequence sequence = new XmlSchemaSequence(); complexType.Particle = sequence; // 创建一个XmlSchemaElement对象 XmlSchemaElement title = new XmlSchemaElement(); title.Name = "title"; title.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(title); // 创建一个XmlSchemaElement对象 XmlSchemaElement author = new XmlSchemaElement(); author.Name = "author"; author.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(author); // 创建一个XmlSchemaKey对象 XmlSchemaKey key = new XmlSchemaKey(); key.Name = "bookKey"; key.Selector = new XmlSchemaXPath("book"); key.Fields.Add(new XmlSchemaXPath("title")); schema.Items.Add(key); // 将XmlSchema对象添加到XmlSchemaSet中 XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); // 编译XmlSchemaSet schemaSet.Compile(); // 输出编译结果 foreach (XmlSchema schema1 in schemaSet.Schemas()) { Console.WriteLine(schema1.TargetNamespace); foreach (XmlSchemaObject schemaObject in schema1.Items) { Console.WriteLine(schemaObject); } } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值