XML deserialization not working - there is an error in XML document (0, 0)

100 views Asked by At

I'm trying to deserialize an XML response but I can't seem to understand what is not working here

These are my classes (generated with the .NET developer tools)

[Serializable]
[XmlType(AnonymousType = true, Namespace = "http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2007-01/calcolaIup/")]
[XmlRoot("GSSC.calcolaIupResponse", Namespace = "http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2007-01/calcolaIup/", IsNullable = false)]
public partial class GSSCcalcolaIupResponse
{
    private param1 paramField;

    /// <remarks/>
    [XmlElementAttribute(Namespace = "")]
    public param1 param
    {
        get
        {
            return this.paramField;
        }
        set
        {
            this.paramField = value;
        }
    }
}

/// <remarks/>
[XmlType(AnonymousType = true)]
public partial class param1
{
    private string iupField;

    /// <remarks/>
    public string iup
    {
        get
        {
            return this.iupField;
        }
        set
        {
            this.iupField = value;
        }
    }
}

The xml response is like this:

<m:GSSC.calcolaIupResponse xmlns:m="http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2013-01/calcolaIup/">
    <param>
        <iup>0000W05RNF</iup>
    </param>
</m:GSSC.calcolaIupResponse>

And here's the code for deserialization.

GSSCcalcolaIupResponse iup = new GSSCcalcolaIupResponse();
XmlSerializer serializer = new XmlSerializer(typeof(GSSCcalcolaIupResponse));

IUPDummyResponse retValue = new IUPDummyResponse();

using (TextReader reader = new StringReader(xml))
{
    if (soapFault == null)
        iup = (GSSCcalcolaIupResponse)serializer.Deserialize(reader);
}
1

There are 1 answers

2
Kim Hoang On BEST ANSWER

The namespace in your class GSSCcalcolaIupResponse and namespace in your xml string are different. It is the reason. Just change to use the same namespace, it will fix the error:

- http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2007-01/calcolaIup/
- http://www.crs.lombardia.it/schemas/DCSanita/GSSC/2013-01/calcolaIup/