0

I've generated classes using the xsd.exe from the AUTOSAR consortium supplied XSD file.

I would like to deserialize the following piece of XML code:

<END-TO-END-PROTECTION-VARIABLE-PROTOTYPES>
    <END-TO-END-PROTECTION-VARIABLE-PROTOTYPE T="2017-07-31T13:37:48Z">
        <RECEIVER-IREFS>
            <RECEIVER-IREF>
                <VARIABLE-DATA-PROTOTYPE-IN-SYSTEM-INSTANCE-REF T="2017-07-31T13:37:48Z">
                    <CONTEXT-COMPOSITION-REF DEST="ROOT-SW-COMPOSITION-PROTOTYPE">/Some/Reference/Value</CONTEXT-COMPOSITION-REF>
                    <TARGET-DATA-PROTOTYPE-REF DEST="VARIABLE-DATA-PROTOTYPE">/Another/Reference/Value</TARGET-DATA-PROTOTYPE-REF>
                </VARIABLE-DATA-PROTOTYPE-IN-SYSTEM-INSTANCE-REF>
            </RECEIVER-IREF>
        </RECEIVER-IREFS>
    </END-TO-END-PROTECTION-VARIABLE-PROTOTYPE>
</END-TO-END-PROTECTION-VARIABLE-PROTOTYPES>

But unfortunately the <RECEIVER-IREF> content was not serialized.

The generated classes for the access are the following:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="END-TO-END-PROTECTION-VARIABLE-PROTOTYPE", Namespace="http://autosar.org/schema/r4.0")]
public partial class ENDTOENDPROTECTIONVARIABLEPROTOTYPE {
    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute("RECEIVER-IREFS", Order=0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("RECEIVER-IREF", IsNullable=false)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREF[] RECEIVERIREFS;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string S;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("SENDER-IREF", Order=1)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREF SENDERIREF;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("SHORT-LABEL", Order=2)]
    public IDENTIFIER SHORTLABEL;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string T;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("VARIATION-POINT", Order=3)]
    public VARIATIONPOINT VARIATIONPOINT;
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="VARIABLE-DATA-PROTOTYPE-IN-SYSTEM-INSTANCE-REF", Namespace="http://autosar.org/schema/r4.0")]
public partial class VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREF {
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("CONTEXT-COMPONENT-REF", Order=0)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFCONTEXTCOMPONENTREF[] CONTEXTCOMPONENTREF;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("CONTEXT-COMPOSITION-REF", Order=1)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFCONTEXTCOMPOSITIONREF CONTEXTCOMPOSITIONREF;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("CONTEXT-PORT-REF", Order=2)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFCONTEXTPORTREF CONTEXTPORTREF;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string S;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string T;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("TARGET-DATA-PROTOTYPE-REF", Order=3)]
    public VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFTARGETDATAPROTOTYPEREF TARGETDATAPROTOTYPEREF;
}

The generated classes seem to be correct and the XML tag structure too. I have no further idea why this is not deserialized.

Does anybody have any idea about the rootcause of this?

  • We need to see a [mcve] to help you. 1) *I've generated classes using the xsd.exe from the AUTOSAR consortium supplied XSD file* - Then please share the XSD. 2) The c# classes you show don't remotely correspond to the XML shown in your question -- the namespace is wrong, for example. 3) Your code cannot be compiled because many class definitions are missing, e.g. `VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFCONTEXTCOMPOSITIONREF` and `VARIABLEDATAPROTOTYPEINSYSTEMINSTANCEREFCONTEXTPORTREF`. See [ask] and https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ – dbc Sep 24 '17 at 19:13
  • To get an idea of the XML that your classes can deserialize, you can serialize them instead. Check https://dotnetfiddle.net/IFRnwu where you will see that the XML generated has several fewer levels than the XML in your question, even accounting for the fact that I had to comment out many members referring to missing types. – dbc Sep 24 '17 at 19:33
  • Thank you for the suggestion. I tried the serialization and now i see that only the VARIABLE-DATA-PROTOTYPE-IN-SYSTEM-INSTANCE-REF level is missing. The xsd file is the AUTOSAR_4-0-3_COMPACT.xsd form the https://www.autosar.org/fileadmin/files/standards/classic/4-0/methodology-templates/templates/standard/AUTOSAR_MMOD_XMLSchema.zip – Tamás Varga Sep 24 '17 at 21:27
  • You should not try to create software on the basis of the compact schema, it has not been designed for that. – Uwe Honekamp Sep 25 '17 at 04:05
  • What I usually do is to fill my classes with test data and serialize the data to a file. Then open xml file with a text editor and compare serialized data with expected results. Then I can tell exactly what is wrong with the class definitions. – jdweng Sep 25 '17 at 04:21
  • Could you explain please why to avoid the compact schema? – Tamás Varga Sep 25 '17 at 07:59
  • The compact schema is the official schema with all groups removed. Therefore, it isn't "compact" at all, and the removal of the groups leads to a loss of information in comparison to the official schema. If you need to take a schema take the official one, and **only** the official one. Not the "compact" or (god forbid) the "strict" one. – Uwe Honekamp Sep 25 '17 at 10:34
  • @UweHonekamp if you like to take a look at the readme.txt inside the linked zip, you will get a nearly diametrically different impression. "optimized" . – Vroomfondel Oct 02 '17 at 07:48
  • @Vroomfondel: it depends on what you want to achieve. Again, the compact schema eliminates the groups and thereby the effort for the parser. It almost certainly is, however, not optimised for the purpose of the original poster. Also, the compact schema is not even part of the official standard, it is an auxiliary deliverable. – Uwe Honekamp Oct 02 '17 at 15:27
  • Thank you for the tips Guys. Now I understand, but unfortunately I cannot try with the normal schema because the xsd.exe stops with circular reference error when generating classes from it and I did not found any free solution for that. But this not occurs when I'm using the compact schema. That was the reason why I'm using it. – Tamás Varga Oct 09 '17 at 15:19

0 Answers0