如何使用ref =" xs:schema"转换xsd类型属性进入c#类?

时间:2016-11-22 05:59:02

标签: c# xml xsd

我试图将以下xml架构中的TSFType转换为c#类。但我不知道如何处理<xs:element ref="xs:schema"/>。有什么建议吗?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:IEEE-1641:2010:STDTSF"
 elementFormDefault="qualified" 
 attributeFormDefault="unqualified" 
 tsf="urn:IEEE-1641:2010:STDTSF"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="TSFType">
        <xs:sequence>
            <xs:element name="interface">
                <xs:complexType>
                    <xs:sequence>
                        <xs:annotation>
                            <xs:documentation>Any XMLSchema definition can be used whose element/attribute types map onto a 1641 type</xs:documentation>
                        </xs:annotation>
                        <xs:element ref="xs:schema"/>
                        <!--xs:any namespace="http://www.w3.org/2001/XMLSchema" processContents="strict" maxOccurs="unbounded"/-->
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:NCName" use="required"/>
    </xs:complexType>

    <xs:element name="TSFLibrary">
        <xs:annotation>
            <xs:documentation>TSFLibrary represents the IEEE 1641 intechangeable Signal Model Library</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="description" type="string" minOccurs="0"/>
                <xs:element name="TSF" type="tsf:TSFType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:NCName" use="required"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

整个xsd可用here

我尝试过xsd.exe,它为未定义架构类型的接口元素提供了以下不正确的类。

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:IEEE-1641:2010:STDTSF")]
public partial class TSFTypeInterface {

    private schema schemaField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.w3.org/2001/XMLSchema")]
    public schema schema {
        get {
            return this.schemaField;
        }
        set {
            this.schemaField = value;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

你运行这个命令了吗? xsd STDTSF.xsd STDBSC.xsd /c

请改为尝试:xsd STDTSF.xsd XMLSchema.xsd STDBSC.xsd /c 它会产生很多东西,包括以下类

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.w3.org/2001/XMLSchema")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.w3.org/2001/XMLSchema", IsNullable=false)]
public partial class schema : openAttrs {

    private openAttrs[] itemsField;

    private topLevelSimpleType[] simpleTypeField;

    private topLevelComplexType[] complexTypeField;

    private namedGroup[] groupField;

    private namedAttributeGroup[] attributeGroupField;

    private topLevelElement[] elementField;

您需要的XSD位于:https://www.w3.org/2001/XMLSchema.xsd

我制作了该文件的pastebin,以防您遇到任何问题 http://pastebin.com/4upNhiB1