I have an xsd that I want to look a certain way serialized. I can achieve what I want with the following but the problem is, xsd2code generates an extra class that's completely unused anywhere. Am I doing it wrong? Is there another trick I am missing?
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" >
<xsd:element name="UITranslatorConfiguration" >
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Queries" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Queries">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Query" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Query">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="QueryID" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
xml output I want:
<UITranslatorConfiguration>
<Queries>
<Query QueryID="queryID1">someQueryText</Query>
<Query QueryID="queryiq2">someQueryText2</Query>
<Query QueryID="queryiq3">someQueryText3</Query>
</Queries>
<UITranslatorConfiguration>
The code it generates:
this is fine:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class UITranslatorConfiguration {
[EditorBrowsable(EditorBrowsableState.Never)]
private List<Query> queriesField;
private static System.Xml.Serialization.XmlSerializer serializer;
public UITranslatorConfiguration() {
this.queriesField = new List<Query>();
}
[System.Xml.Serialization.XmlArrayAttribute(Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("Query", IsNullable=false)]
public List<Query> Queries {
get {
return this.queriesField;
}
set {
this.queriesField = value;
}
}
}
this is fine:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class Query {
[EditorBrowsable(EditorBrowsableState.Never)]
private string queryIDField;
[EditorBrowsable(EditorBrowsableState.Never)]
private string valueField;
private static System.Xml.Serialization.XmlSerializer serializer;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string QueryID {
get {
return this.queryIDField;
}
set {
this.queryIDField = value;
}
}
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
This is not fine. Where did this come from and why? It's not used anywhere at all. How do I make xsd2code not generate this class.
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class Queries {
[EditorBrowsable(EditorBrowsableState.Never)]
private List<Query> queryField;
private static System.Xml.Serialization.XmlSerializer serializer;
public Queries() {
this.queryField = new List<Query>();
}
[System.Xml.Serialization.XmlElementAttribute("Query", Order=0)]
public List<Query> Query {
get {
return this.queryField;
}
set {
this.queryField = value;
}
}
}