Some parts of XML not deserialized (inheritance?)

Jan 22, 2013 at 2:54 PM


We have a XSD (BRKLeveringGemeenteGebaseerdeStand_v1_1_4). We created c# classes from this XSD (which uses quite a lot imports of other XSD's).

1. We validate the given xml agains the xsd. No error occurres.
2. We deserialize the cxml to the object. No error.
3. But when we look into the object some objects have a 'null' value while data exists in the XML file.

The XML file:

<?xml version="1.0" encoding="UTF-8"?><!--Created by GO Publisher Agent 1.4.5-SNAPSHOT Build 25198 from 2011-09-20 12:51--><!--Snowflake Software Ltd. (><GemeenteGebaseerdeStand:GemeenteGebaseerdeStand xmlns:xsi="" xmlns:xs="" xmlns:GemeenteGebaseerdeStand="" xmlns:Typen="" xmlns:Snapshot="" xmlns:GbaPersoon="" xmlns:Adres="" xmlns:Persoon="" xmlns:NEN3610="" xmlns:BagAdres="" xmlns:KadastraalObject="" xmlns:InOnderzoek="" xmlns:KadastraalObjectRef="" xmlns:xlink="" xmlns:gml="" xmlns:smil20="" xmlns:smil20lang="" xmlns:NhrRechtspersoon="" xmlns:Recht="" xmlns:GbaPersoonRef="" xmlns:PersoonRef="" xmlns:NhrRechtspersoonRef="" xmlns:RechtRef="" xmlns:StukRef="" xmlns:Stuk="" xsi:schemaLocation=" BRKLeveringGemeenteGebaseerdeStand_v1_1_4.xsd">
<KadastraalObject:Perceel id="ID.50667496">
<Adres:openbareRuimteNaam>DE GAARDE</Adres:openbareRuimteNaam>
 The XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:GemeenteGebaseerdeStand="" xmlns:Typen="" xmlns:Snapshot="" xmlns:xs="" targetNamespace="" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.1.4">
		<xs:appinfo source=""></xs:appinfo>
		<xs:appinfo source="">1.1.4</xs:appinfo>
		<xs:appinfo source="">20120901</xs:appinfo>
		<xs:appinfo source="">$Id$</xs:appinfo>
		<xs:documentation source="">Bestandsnaam: BRKLeveringGemeenteGebaseerdeStand_v1_1_4.xsd / 
        Dit schema is samengesteld in overeenstemming met de codeerregels vastgelegd in  
        ISO 19118: Text of 19118 Geographic information - Encoding, as sent to the ISO Central 
        Secretariat for publication
		<xs:documentation source="">TODO</xs:documentation>
	<xs:import namespace="" schemaLocation="../../snapshot/imkad-typen/v20120201/BRKLeveringImkadTypen_v1_1_0.xsd"/>
	<xs:import namespace="" schemaLocation="../../snapshot/v20120901/BRKLeveringSnapshot_v1_1_4.xsd"/>
	<xs:element name="GemeenteGebaseerdeStand" type="GemeenteGebaseerdeStand:GemeenteGebaseerdeStand" abstract="false"/>
	<xs:complexType name="GemeenteGebaseerdeStand" abstract="false">
			<xs:documentation source="">Definitie
Een BRK Stand kan gebaseerd worden op basis van verschillende selectiecriteria. Als eerste wordt de Gemeente Gebaseerde Stand ge�mplementeerd.</xs:documentation>
			<xs:element name="BRKDatum" type="xs:date">
					<xs:documentation source="">De (peil)datum waarmee de selectie van de stand uit de Basisregistratie Kadaster is uitgevoerd.</xs:documentation>
			<xs:element name="naamBurgerlijkeGemeente" type="GemeenteGebaseerdeStand:WaardelijstBurgerlijkeGemeente">
					<xs:documentation source="">De burgerlijke gemeente waarmee de selectie van de totaalstand uit de Basisregistratie Kadaster is uitgevoerd.</xs:documentation>
			<xs:element name="stand" minOccurs="0">
						<xs:element ref="Snapshot:KadastraalObjectSnapshot" maxOccurs="unbounded"/>
	<xs:element name="WaardelijstBurgerlijkeGemeente" type="GemeenteGebaseerdeStand:WaardelijstBurgerlijkeGemeente" abstract="false" substitutionGroup="Typen:Waardelijst"/>
	<xs:complexType name="WaardelijstBurgerlijkeGemeente" abstract="false">
			<xs:extension base="Typen:Waardelijst">

 The object:
After deserialize:

object.stand[0]._KadastraalObject = null 

In the XSD we see a KadastraalObject:Perceel. If we look in the class we see Perceel (inherit from __OnroerendeZaak which inherits from _KadastraalObject).
But the object is never filled.

Here are our XSD2Code settings (only the changes)

 - CollectionObjectType = Array 
- GenerateXmlAttributes = true
- EnableVirtualProperties = true


Has anyone an idea how to solve this problem? 

Jan 23, 2013 at 9:42 AM

I believe I am seeing this same issue - can you look at the constructors in the generated code classes - what I see is in some cases Xsd2Code generaates a constructor that instantiates any sub classes - but in other cases there is no constructor at all even when the class does have some fields that are objects related to "lower" complex types in the XSD.  Obviously a constructor is not needed when the class only has simple types (which are then just simple fields in the class).

What makes this more confusing is that some classes have constructors to deal with their sub objects and others don't - I have not yet worked out why - I assume there is some sort of bug in the way Xsd2Code iterates through the complex types. THere may be some relationship to types being derived by extension or restriction from other types - I am still investigating.  My own XSD is a nasty complex mess provided by another organisation (who I could name and shame) so I need to create a test "smaller" XSD to see what is happening more clearly.

My initial workaround is to find the classes with object fields and no constructors and use a partial class in another code file to add the constructor required.

Jan 23, 2013 at 9:58 AM
Edited Jan 23, 2013 at 10:07 AM

Hello James,


Do you have an example of a classes which is wrong so i can check it with my classes.

And do you have a workaround example?


My file generate from XSD2Code is pretty large ~19000 lines of code.