I am trying to take a XML Schema and covert the relationships to C# classes. The situation I am running into is as follows:
I have a complex type in the schema which has 4 elements all of a certain type:
<xs:complexType name="ReportingBaseType" abstract="true">
<xs:sequence>
<xs:element name="Category" type="ent:ReportingCategoryConceptType" minOccurs="0" maxOccurs="0"/>
<xs:element name="Frequency" type="ent:ReportingFrequencyType"/>
<xs:element name="AdjustmentFrequency" type="ent:ReportingAdjustmentFrequencyType"/>
<xs:element name="FirstReportDueDate" type="ent:CXMLDateType" minOccurs="0" maxOccurs="0"/>
</xs:sequence>
</xs:complexType>
Next, I have multiple complextypes that can restrict or extend this type:
<xs:complexType name="ReportingClassA">
<xs:restriction base="ReportingBaseType">
<xs:sequence>
<xs:element name="Category" type="ent:ReportingClassAType" minOccurs="0" maxOccurs="0"/>
<xs:element name="Frequency" type="ent:FequencyForThisClassType"/>
</xs:sequence>
</restriction>
</xs:complexType>
<xs:complexType name="ReportingClassB">
<xs:restriction base="ReportingBaseType">
<xs:sequence>
<xs:element name="Category" type="ent:NewTypeForThisClass" minOccurs="0" maxOccurs="0"/>
<xs:element name="Frequency" type="ent:AnotherNewType"/>
<xs:element name="AdjustmentFrequency" type="ent:ThisIsADifferntTypeThenParent"/>
<xs:element name="FirstReportDueDate" type="ent:AndAnotherNewType" minOccurs="0" maxOccurs="
</xs:sequence>
</restriction>
</xs:complexType>
How can I (in C#) derive from the parent class (ReportingBaseType) but have different types for the properties like they are defined in the Schema?
I have thought of using the new
keyword when defining my properties on the derived classes to "hide" the inherited members but I have heard that when serializing this object that the XML Serializer may not handle this correctly.
Does anyone have any advice how to correctly relate my schema to C# classes and still be able to serialize my c# objects to correct XML object that will pass the XML Schema Validation?
EDIT: I have tried using Xsd2Code and the built in xsd.exe tool to handle the correct c# classes but they do not generate the detail that I need. Especially in the circumstances that I have described above.
No comments:
Post a Comment