You must Sign In to post a response.
  • Category: WCF

    Problem with .net XMLSerializer deserialization

    I'm have trouble with abstract classes in deserialization of XML with XMLSerializer in .NET

    my input xml looks like :

    <?xml version="1.0" encoding="UTF-8"?>
    <gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:gsr="http://www.isotc211.org/2005/gsr"
    xmlns:gss="http://www.isotc211.org/2005/gss"
    xmlns:gts="http://www.isotc211.org/2005/gts"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:georss="http://www.georss.org/georss"
    xmlns:app="http://www.w3.org/2007/app"
    xmlns:as="http://atomserver.org/namespaces/1.0/"
    xmlns:gml="http://www.opengis.net/gml"
    xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://nap.geogratis.gc.ca/metadata/tools/schemas/metadata/can-cgsb-171.100-2009-a/gmd/gmd.xsd">
    <gmd:identificationInfo>
    <gmd:MD_DataIdentification>
    <gmd:citation>
    <gmd:CI_Citation>
    <gmd:title>
    <gco:CharacterString xmlns:gco="http://www.isotc211.org/2005/gco">Lithoprobe East Seismic Reflection Line 6</gco:CharacterString>
    </gmd:title>
    </gmd:CI_Citation>
    </gmd:MD_DataIdentification>
    </gmd:identificationInfo>
    </gmd:MD_Metadata >


    The C# code generated by xsd.exe for decoding the <gmd:identificationInfo> node looks like this :

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.isotc211.org/2005/gmd")]
    public partial class MD_Identification_PropertyType {

    private AbstractMD_Identification_Type abstractMD_IdentificationField;

    private string uuidrefField;

    private string nilReasonField;

    /// <remarks/>
    public AbstractMD_Identification_Type AbstractMD_Identification {
    get {
    return this.abstractMD_IdentificationField;
    }
    set {
    this.abstractMD_IdentificationField = value;
    }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string uuidref {
    get {
    return this.uuidrefField;
    }
    set {
    this.uuidrefField = value;
    }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://www.isotc211.org/2005/gco")]
    public string nilReason {
    get {
    return this.nilReasonField;
    }
    set {
    this.nilReasonField = value;
    }
    }
    }


    which calls an abstract class , AbstractMD_Identification_Type, which has the MD_DataIdentification tag declared as an XmlIncludeAttribute.

    /// <remarks/>
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(MD_DataIdentification_Type))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.isotc211.org/2005/gmd")]
    public abstract partial class AbstractMD_Identification_Type : AbstractObject_Type {

    private CI_Citation_PropertyType citationField;

    private CharacterString_PropertyType abstractField;

    private CharacterString_PropertyType purposeField;

    private CharacterString_PropertyType[] creditField;

    private MD_ProgressCode_PropertyType[] statusField;

    private CI_ResponsibleParty_PropertyType[] pointOfContactField;

    private MD_MaintenanceInformation_PropertyType[] resourceMaintenanceField;

    private MD_BrowseGraphic_PropertyType[] graphicOverviewField;

    private MD_Keywords_PropertyType[] descriptiveKeywordsField;

    private MD_Constraints_PropertyType[] resourceConstraintsField;

    private MD_AggregateInformation_PropertyType[] aggregationInfoField;

    /// <remarks/>
    public CI_Citation_PropertyType citation {
    get {
    return this.citationField;
    }
    set {
    this.citationField = value;
    }
    }

    /// <remarks/>
    public CharacterString_PropertyType @abstract {
    get {
    return this.abstractField;
    }
    set {
    this.abstractField = value;
    }
    }

    /// <remarks/>
    public CharacterString_PropertyType purpose {
    get {
    return this.purposeField;
    }
    set {
    this.purposeField = value;
    }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("credit")]
    public CharacterString_PropertyType[] credit {
    get {
    return this.creditField;
    }
    set {
    this.creditField = value;
    }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("status")]
    public MD_ProgressCode_PropertyType[] status {
    get {
    return this.statusField;
    }
    set {
    this.statusField = value;
    }
    }

    My problem is that the XMLSerializer does not deserialize the content within the xml block:

    <gmd:MD_DataIdentification>
    <gmd:citation>
    <gmd:CI_Citation>
    <gmd:title>
    <gco:CharacterString xmlns:gco="http://www.isotc211.org/2005/gco">Lithoprobe East Seismic Reflection Line 6</gco:CharacterString>
    </gmd:title>
    </gmd:CI_Citation>
    </gmd:MD_DataIdentification>

    It will work if I substitute
    private AbstractMD_Identification_Type abstractMD_IdentificationField;

    in the C# code with
    private MD_DataIdentification_Type abstractMD_IdentificationField;



    Should not the

    [System.Xml.Serialization.XmlIncludeAttribute(typeof(MD_DataIdentification_Type))]

    statement do this for me?

    Any comments?

    Bob
  • #754700
    What and where is the problem can you please provide the exact piece of code where you are having issue, rather than posting the complete page code.
    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments