I have an XSD describing the schema for some of my data contracts in an application I am building. I'm not the most experienced in writing xsd files, but so far nothing I've tried has been able to resolve my issue.
I have a section of the schema that looks like this:
<xs:complexType name="RecordSetDefinition">
<xs:sequence>
<xs:element name="RecordId" type="RecordIdDefinition" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="Record" type="RecordDefinition" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Id" type="xs:string" />
</xs:complexType>
The XML that this corresponds to looks like:
<RecordSet Id="Test">
<RecordId ...>
...
</RecordId>
<RecordId ...>
...
</RecordId>
<Record ...>
...
</Record>
<Record ...>
...
</Record>
<Record ...>
...
</Record>
</RecordSet>
The idea is that my data contract for the RecordSetDefinition
has an array of RecordIdDefinition
s and RecordDefinition
s. Running the generate command:
xsd \c \l:cs
Produces:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="...")]
public partial class RecordSetDefinition {
private RecordIdDefinition[] recordIdField;
private RecordDefinition[] recordField;
private string idField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("RecordId")]
public RecordIdDefinition[] RecordId {
get {
return this.recordIdField;
}
set {
this.recordIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Record")]
public RecordDefinition[] Record {
get {
return this.recordField;
}
set {
this.recordField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
}
Which is all fine and dandy...except that the names of the properties containing the arrays of definitions are singular, not plural.
Question:
To aid in code comprehension, I'd like to have these names pluralized (i.e. RecordIds
instead of RecordId
). Is this possible to do using the XSD so that xsd.exe
will generate plural array names in C# while still maintaining the individual element names singular in XML?
The XML is arbitrary and can be changed, but so far I can't seem to find a permutation of the schema that gives me my desired outcome. The closest I've gotten is making an element called RecordIds
which contains the individual RecordId
records, but that still results in a rather unintuitive RecordIds.RecordId[]
property. Using the xs:choice
would generate RecordIds.Items[]
which would work, but I'd like to know if there is a better way.
I can't just modify the generated code since obviously it would be overwritten the next time we generate the .cs
files from the .xsd
and that poses maintainability issues for the next developer who comes along.