XSD.exe限制基类型属性

时间:2012-10-17 13:56:25

标签: c# xml xsd.exe

通过在XSD上的元素之前提供注释属性,是否可以使用XSD.exe自动生成具有与XSD中指定的属性不同的属性的类。

这个想法是,保持XSD的方式,但希望自动生成的类具有特定属性的不同数据类型。

<xsd:simpleType name="idRestriction">
<Specify_Custom_Type="xsd:string" //This is what I'm looking for
<xsd:restriction base="xsd:decimal">

<xsd:attribute name="idAttribute" type="idRestriction" use="required" />

生成的课程

[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal id { // Would like the decimal to be string
get {
            return this.idField;
        }
        set {
            this.idField = value;
        }
    }

我希望它生成什么

[System.Xml.Serialization.XmlAttributeAttribute()]
public string id { // Notice decimal --> string
get {
            return this.idField;
        }
        set {
            this.idField = value;
        }
    }

1 个答案:

答案 0 :(得分:1)

假设您有schema.xsd个文件

如果您将同一文件复制为schema2.xsd并将所有其他基本类型替换为字符串,则可以使用此文件生成.cs

如果您通过编写批处理文件来自动执行此过程,我认为您的问题可以解决。

以下链接包含有关如何替换文本文件内容的问题。请检查那个

How can you find and replace text in a file using the Windows command-line environment?

我想提一下,从这些文件生成.cs文件时,有一点是类名相同。因此,最好为这两个类使用不同的名称空间,这样生成的类类型就不会发生冲突。

您可以使用/n

xsd.exe参数来提及命名空间

请在下面查看xsd.exe命令行参数

的链接

http://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.110).aspx

相关问题