XML : Having issue desrializing string with XSD

I'm having trouble trying to deserialise an XML string using an XSD. I'm using c#/Asp.Net along with the DataContractSerializer.

Here's the string as it's returned from a third party:

  `<ApplicationResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Id>11625807</Id><Status>Declined</Status><Response>1</Respons`e><Price /><Detail>No Qualified Buyers Found</Detail></ApplicationResponse>    

Here's the class I'm trying to create:

  [DataContract(Name = "ApplicationResponse", Namespace = "")]  public class SCFResponse  {      [DataMember]      public string Id { get; set; }        [DataMember]      public string Status { get; set; }        [DataMember]      public string Response { get; set; }        [DataMember]      public decimal Price { get; set; }        [DataMember]      public string Detail { get; set; }  }    

It all works fine until I try to validate against my XSD. I'm not an expert here so it's probably something simple.

Incidentally what, I'm trying to achieve, and maybe incorrectly is to validate one against one of the "accepted, "declined" or "rejected" subparts.

  <?xml version="1.0" encoding="utf-8"?>  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">    <xs:element name="ApplicationResponse" type="root"/>      <xs:complexType name="root">      <xs:sequence>        <xs:element name="accepted" type="acceptedLead"/>        <xs:element name="declined" type="declinedLead"/>        <xs:element name="rejected" type="rejectedLead"/>      </xs:sequence>    </xs:complexType>      <xs:complexType name="acceptedLead">      <xs:sequence>        <xs:element name="Id" type="id"/>        <xs:element name="Status" type="acceptedStatus"/>        <xs:element name="Price" type="price"/>        <xs:element name="Detail" type="url"/>      </xs:sequence>    </xs:complexType>      <xs:complexType name="declinedLead">      <xs:sequence>        <xs:element name="Id" type="id"/>        <xs:element name="Status" type="declinedStatus"/>      </xs:sequence>    </xs:complexType>      <xs:complexType name="rejectedLead">      <xs:sequence>        <xs:element name="Status" type="rejectedStatus"/>      </xs:sequence>    </xs:complexType>      <xs:simpleType name="acceptedStatus">      <xs:restriction base="xs:string">        <xs:enumeration value="Accepted"/>      </xs:restriction>    </xs:simpleType>      <xs:simpleType name="declinedStatus">      <xs:restriction base="xs:string">        <xs:enumeration value="Declined"/>      </xs:restriction>    </xs:simpleType>      <xs:simpleType name="rejectedStatus">      <xs:restriction base="xs:string">        <xs:enumeration value="Rejected"/>      </xs:restriction>    </xs:simpleType>      <xs:simpleType name="id">      <xs:restriction base="xs:string">        <xs:enumeration value="([0-9])+"/>      </xs:restriction>    </xs:simpleType>      <xs:simpleType name="price">      <xs:restriction base="xs:decimal">        <xs:minInclusive value="0.00"/>        <xs:maxInclusive value="100.00"/>      </xs:restriction>    </xs:simpleType>      <xs:simpleType name="url">      <xs:restriction base="xs:anyURI">        <xs:pattern value="https://.+" />      </xs:restriction>    </xs:simpleType>    </xs:schema>    

Here's the message I'm logging:

  The element 'ApplicationResponse' has invalid child element 'Id'. List of possible elements expected: 'accepted'.|Stack: 0 - Xml:129;    

Any advice appreciated.

No comments:

Post a Comment