ricky
ricky

Reputation: 2108

How to convert a xsd type with ref="xs:schema" attribute into c# class?

I'm trying to convert TSFType in the following xml schema to a c# class. But I don't know how to deal with <xs:element ref="xs:schema"/>. Any suggestion?

<?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>

The entire xsd is available here.

I have tried xsd.exe, and it give the following incorrect class for interface element in which the schema type is not defined.

[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;
        }
    }
}

Upvotes: 1

Views: 1182

Answers (1)

Hannott
Hannott

Reputation: 116

Did you run this command? xsd STDTSF.xsd STDBSC.xsd /c

Try this instead: xsd STDTSF.xsd XMLSchema.xsd STDBSC.xsd /c It will generate a lot of stuff, including the following class

/// <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;

The XSD you need is found here: https://www.w3.org/2001/XMLSchema.xsd

I made a pastebin of the file, in case you have any issues http://pastebin.com/4upNhiB1

Upvotes: 2

Related Questions