Question

I have a problem with serializing an object. That object is generated from a XSD-file.

This are the elements from the XSD:

<xs:element name="ResGuestRPHs" type="ResGuestRPHsType" minOccurs="0">
    <xs:annotation>
        <xs:documentation xml:lang="en">A collection of ResGuestRPH objects. </xs:documentation>
    </xs:annotation>
</xs:element>

<xs:complexType name="ResGuestRPHsType">
    <xs:annotation>
        <xs:documentation xml:lang="en">A collection of unsigned integers serving as reference placeholders, and used as an index identifying which guests occupy this room</xs:documentation>
    </xs:annotation>
    <xs:simpleContent>
        <xs:extension base="ListOfRPH"/>
    </xs:simpleContent>
</xs:complexType>

<xs:simpleType name="ListOfRPH">
    <xs:annotation>
        <xs:documentation xml:lang="en">List of Reference Place Holders.</xs:documentation>
    </xs:annotation>
    <xs:list itemType="RPH_Type"/>
</xs:simpleType>

<xs:simpleType name="RPH_Type">
    <xs:annotation>
        <xs:documentation xml:lang="en">The Reference Place Holder (RPH) is an index code used to identify an instance in a collection of like items (e.g. used to assign individual passengers or clients to particular itinerary items).</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{1,8}"/>
    </xs:restriction>
</xs:simpleType>

This element should output after serialization as (notice the space between the numbers to indicate it are 2 elements of the list):

<ResGuestRPHs>1 2</ResGuestRPHs>

But is it generate without the space what results in deserializing to only 1 element:

<ResGuestRPHs>12</ResGuestRPHs>

This is the generated object:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.opentravel.org/OTA/2003/05")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.opentravel.org/OTA/2003/05", IsNullable=true)]
public partial class ResGuestRPHsType
{

    private System.Collections.Generic.List<string> textField;

    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public System.Collections.Generic.List<string> Text
    {
        get
        {
            return this.textField;
        }
        set
        {
            this.textField = value;
        }
    }
}

This is generated with "WSCF.blue". When I change the List to an Array it gives the same problem. When I use it as "XmlAttributeAttribute" is works (but it doesn't validate with the XSD ofcourse).

Does anybody knows why this is not serializing correctly?

Was it helpful?

Solution

At the moment I use the following 'dirty' solution. When adding to the list, I manually add a space (resGuestRPH is the variable to add):

ResGuestRPHs.Text.Add(resGuestRPH + " ");

When reading the list, I manually split the string:

ResGuestRPHs.Text = ResGuestRPHs.Text.First().Trim().Split(' ').ToList();

This way the XML validates with the XSD but I still hope someone can help me to find a 'clean' solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top