xsd.exe用字符串替换我的自定义类型

时间:2015-10-22 07:10:39

标签: c# .net xml xsd

我使用xsd.exe从XSD架构生成C#类。这是我在架构中的内容:

<xs:element name="SyslogServerSettings" type="SyslogServerType"/>
    <xs:complexType name="SyslogServerType">
        <xs:annotation>
            <xs:appinfo>
                <meta:version added-in="5.11" />
                <meta:content-type>application/vnd.vmware.vcloud.SyslogSettings</meta:content-type>
            </xs:appinfo>
            <xs:documentation source="since">5.11</xs:documentation>
            <xs:documentation xml:lang="en">
                Allows a user to configure syslog server settings for the gateway
            </xs:documentation>
        </xs:annotation>

        <xs:complexContent>
            <xs:extension base="VCloudExtensibleType">
                <xs:sequence>
                    <xs:element name="TenantSyslogServerSettings"
                        type="TenantSyslogServerSettingsType" minOccurs="0"
                        maxOccurs="1">
                        <xs:annotation>
                            <xs:appinfo>
                                <meta:version added-in="5.11" />
                            </xs:appinfo>
                            <xs:documentation source="modifiable">always
                            </xs:documentation>
                            <xs:documentation xml:lang="en">
                                Tenant syslog server settings
                            </xs:documentation>
                            <xs:documentation source="required">false
                            </xs:documentation>
                        </xs:annotation>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

还有TenantSyslogServerSettings的定义:

<xs:complexType name="TenantSyslogServerSettingsType">
        <xs:annotation>
            <xs:documentation source="since">5.11</xs:documentation>
            <xs:documentation xml:lang="en">
                Tenant syslog server settings.
                If logging is configured for firewall rules, the logs will be directed to these syslog servers
                along with the provider syslog servers.
                Only one tenant syslog server ip can be configured.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="SyslogServerIp" type="IpAddressType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation source="modifiable">always</xs:documentation>
                    <xs:documentation xml:lang="en">
                        syslog server ip address.
                    </xs:documentation>
                    <xs:documentation source="required">false</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

另一方面,IpAddressType定义为:

<xs:simpleType name="IpAddressType">
        <xs:annotation>
            <xs:documentation source="since">0.9</xs:documentation>
            <xs:documentation xml:lang="en">
                A valid IPv4 address or "Any".
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
        </xs:restriction>
    </xs:simpleType>

在最终生成的C#类中,我得到了:

[System.Xml.Serialization.XmlRootAttribute("SyslogServerSettings", Namespace="http://www.vmware.com/vcloud/v1.5", IsNullable=false)]
    public partial class SyslogServerType : VCloudExtensibleType {

        private string[] tenantSyslogServerSettingsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("SyslogServerIp", IsNullable=false)]
        public string[] TenantSyslogServerSettings {
            get {
                return this.tenantSyslogServerSettingsField;
            }
            set {
                this.tenantSyslogServerSettingsField = value;
            }
        }
    }

我可以得到用string []替换自定义类型的逻辑,但这不是我想要的。我想要生成自定义类型TenantSyslogServerSettings,即使它只是一个包含一个字符串属性的类。如何让xsd.exe生成它?

0 个答案:

没有答案