Hi,
I have a schema that has an optional element, fieldTag4000Fie ld. If the
element is omitted from the XML request, when it is deserialized, it will be
null when I check it - which is fine.
What happens when the element is supplied as <fieldTag4000Fi eld/(empty),
it does not equate to null. I want to be able handle this at the
deserialization level rahter than in my edits later.
Is there a way to alter the behavior so when I deserialize it, it is null?
I also want to add that I am calling the "CanDeserialize " method of the
XmlSerializer object, passing in the request as a XmlNodeReader.
Thanks.
The following C# class snippet was generated by xsd.exe V2:
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {
private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {
private IDType_Type intermediaryIDC odeField;
private bool intermediaryIDC odeFieldSpecifi ed;
private string intermediaryIde ntifierField;
public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {
B,
C,
D,
F,
U,
}
I have a schema that has an optional element, fieldTag4000Fie ld. If the
element is omitted from the XML request, when it is deserialized, it will be
null when I check it - which is fine.
What happens when the element is supplied as <fieldTag4000Fi eld/(empty),
it does not equate to null. I want to be able handle this at the
deserialization level rahter than in my edits later.
Is there a way to alter the behavior so when I deserialize it, it is null?
I also want to add that I am calling the "CanDeserialize " method of the
XmlSerializer object, passing in the request as a XmlNodeReader.
Thanks.
The following C# class snippet was generated by xsd.exe V2:
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {
private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {
private IDType_Type intermediaryIDC odeField;
private bool intermediaryIDC odeFieldSpecifi ed;
private string intermediaryIde ntifierField;
public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {
B,
C,
D,
F,
U,
}
Comment