XSD.exe tool creates properties with "Specified" postfix.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have the following schemas. when i use XSD.exe tool to generate C# classes, then the resulting class has one extra boolean property "MaleSpecified". When i serialize the class the XML serializer does not serialize the "Male" property even i have value
set. In Order to Serialize the "Male" property i also have to set MaleSpecified = true. Why? and also it looks like it only generates property with "Specified" postfix for restriction type and who minoccurrs=0 and maxoccurrs=1
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; schema <span style="color:Red; xmlns:xs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema<span style="color:Black; "
<span style="color:Red; elementFormDefault<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; qualified<span style="color:Black; "
<span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; BaseSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; simpleType <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yesNoType<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; restriction <span style="color:Red; base<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; xs:string<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; enumeration <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Yes<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; enumeration <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; No<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; restriction<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; simpleType<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; schema<span style="color:Blue; >

<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; schema <span style="color:Red; xmlns:xs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema<span style="color:Black; "
<span style="color:Red; elementFormDefault<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; qualified<span style="color:Black; "
<span style="color:Red; attributeFormDefault<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; unqualified<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; include <span style="color:Red; schemaLocation<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; BaseSchema.xsd<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppealRoot<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; complexType<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; sequence<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AppealForm<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; complexType<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; sequence<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; FirstName<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; xs:string<span style="color:Black; " <span style="color:Red; minOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; maxOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LastName<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; xs:string<span style="color:Black; " <span style="color:Red; minOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; maxOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Male<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yesNoType<span style="color:Black; " <span style="color:Red; minOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; maxOccurs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; sequence<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; complexType<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; sequence<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; complexType<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; element<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xs<span style="color:Blue; :<span style="color:#A31515; schema<span style="color:Blue; >

[/code]

<div style="color:Black;background-color:White; <pre>
<span style="color:Green; //------------------------------------------------------------------------------
<span style="color:Green; // <auto-generated>
<span style="color:Green; // This code was generated by a tool.
<span style="color:Green; // Runtime Version:4.0.30319.225
<span style="color:Green; //
<span style="color:Green; // Changes to this file may cause incorrect behavior and will be lost if
<span style="color:Green; // the code is regenerated.
<span style="color:Green; // </auto-generated>
<span style="color:Green; //------------------------------------------------------------------------------

<span style="color:Green; //
<span style="color:Green; // This source code was auto-generated by xsd, Version=4.0.30319.1.
<span style="color:Green; //
<span style="color:Blue; namespace TestApplication.Schema {
<span style="color:Blue; using System.Xml.Serialization;


<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute(<span style="color:#A31515; "xsd", <span style="color:#A31515; "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(<span style="color:#A31515; "code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=<span style="color:Blue; true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace=<span style="color:#A31515; "", IsNullable=<span style="color:Blue; false)]
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class AppealRoot {

<span style="color:Blue; private AppealRootAppealForm appealFormField;

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
<span style="color:Blue; public AppealRootAppealForm AppealForm {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.appealFormField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.appealFormField = value;
}
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute(<span style="color:#A31515; "xsd", <span style="color:#A31515; "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(<span style="color:#A31515; "code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=<span style="color:Blue; true)]
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class AppealRootAppealForm {

<span style="color:Blue; private <span style="color:Blue; string firstNameField;

<span style="color:Blue; private <span style="color:Blue; string lastNameField;

<span style="color:Blue; private yesNoType maleField;

<span style="color:Blue; private <span style="color:Blue; bool maleFieldSpecified;

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
<span style="color:Blue; public <span style="color:Blue; string FirstName {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.firstNameField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.firstNameField = value;
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
<span style="color:Blue; public <span style="color:Blue; string LastName {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.lastNameField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.lastNameField = value;
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
<span style="color:Blue; public yesNoType Male {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.maleField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.maleField = value;
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
<span style="color:Blue; public <span style="color:Blue; bool MaleSpecified {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.maleFieldSpecified;
}
<span style="color:Blue; set {
<span style="color:Blue; this.maleFieldSpecified = value;
}
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute(<span style="color:#A31515; "xsd", <span style="color:#A31515; "4.0.30319.1")]
[System.SerializableAttribute()]
<span style="color:Blue; public <span style="color:Blue; enum yesNoType {

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
Yes,

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
No,
}
}
[/code]

View the full article
 
Back
Top