C#, XSD.exe, xsd2code and generating nullable fields+properties from an XSD with and without Specified fields/properties
Posted by jpluimers on 2016/07/27
It comes down to these cases for XML elements
having maxOccurs="1"
(which the default for maxOccurs
):
- adding
nillable="true"
will convert from a regular type to a nullable type. - adding
minOccurs="0"
will add boolean …Specified properties in the generated C# for each element. - you can have both
nillable="true"
andminOccurs="0"
in an element which gets you a nullable type and a …Specified property.
Note I’m not considering
fixed
ordefault
here, norattributes
(that haveuse
instead ofminOccurs
/maxOccurs
, but do not allow for nillable) nor larger values ofmaxOccurs
(which both xsd.exe and xsd2code regard asunbounded
).
From the above, XML has a richer type system than C#, so in XML there are subtle a differences between:
- an explicit
nil
in the XML element - the XML element being absent
- the XML element being empty.
Hopefully later more text and examples to show how to actually work with this.
- XML Schema nillable=”true” vs minOccurs=”0″ | Dimuthu’s Blog.
- Web services tip: Representations of null in XML Schema.
- c# – Nullable value with xsd.exe genereated class – Stack Overflow.
- Simon Fell > Its just code > Nullable and XxxSpecified.
- Knucklebones: How to NOT use XSD.EXE (it mentions xsd2code which is maintained and XmlGen# which is not maintained).
- Nullable type and XML xsd.exe tool – .NET Development – Windows Tech (xsd.exe .NET DataSets code generation don’t support Nullable).
- c# – Comparison of XSD Code Generators – Stack Overflow.
- .net – Serialize nullable type to optional non-nillable element – Stack Overflow.
- c# – Setting minOccurs=0 in a WSDL using “Specified” pattern not working – Stack Overflow.
- c# – Is it valid to set nillable=true and use the default property in an XML document? – Stack Overflow.
- xml – nillable and minOccurs XSD element attributes – Stack Overflow.
- Web services tip: Representations of null in XML Schema.
- XSD tool appends “Specified” to certain properties/fields when generating C# code – Stack Overflow: watch for semantics differences between C# and XML.
- Using the *Specified Properties in Exchange 2010.
- Name of the blog | Xml Serialization.
- c# – Nullable value with xsd.exe genereated class – Stack Overflow.
Delphi related to minOccurs
:
- [WayBack] Problem with optional parameters in a remote function – delphi
- Wayback Machine QC 24056 is unavailable
- [WayBack] QualityCentral 73096 – Reported – Missing empty line in auto-generated code for node collections
- [RSP-16448] WSDL Importer has problems with tags in berlin – Embarcadero Technologies
- [RSP-19690] XML Data Binding Wizard creates wrong datatype – Embarcadero Technologies
- [WayBack] Delphi XML binding wizard and optional elements – Stack Overflow
Note that xsd2code.codeplex.com (unlike XmlGen#) has at least two forks at github:
From the specs:
- XML Schema Part 0: Primer Second Edition.
- XML Schema Part 1: Structures Second Edition.
- XSD.exe XML Schema Binding Support:
- XML Schemas (XSD) Reference:
–jeroen
Leave a Reply