I have an XML string resposne that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response ResponseReference="REF_D_026_145-2601465218898798">
<ResponseDetails Language="en">
<SearchHotelPriceResponse>
<HotelDetails>
<Hotel HasExtraInfo="true" HasMap="true" HasPictures="true">
<City Code="LON">
<![CDATA[London]]>
</City>
<Item Code="IBI3">
<![CDATA[IBIS EXCEL]]>
</Item>
<LocationDetails>
<Location Code="G9">
<![CDATA[Outside Centre]]>
</Location>
<Location Code="01">
<![CDATA[Docklands]]>
</Location>
</LocationDetails>
<StarRating>3</StarRating>
<HotelRooms>
<HotelRoom Code="DB" NumberOfRooms="1"/>
</HotelRooms>
<RoomCategories>
<RoomCategory Id="001:IBI3:17082:S16700:22530:91760">
<Description>
<![CDATA[Standard Twin]]>
</Description>
<ItemPrice CommissionPercentage="0.00" Currency="USD">1870.00</ItemPrice>
<Confirmation Code="IM">
<![CDATA[AVAILABLE]]>
</Confirmation>
<Meals>
<Basis Code="B">
<![CDATA[Breakfast]]>
</Basis>
<Breakfast Code="F">
<![CDATA[Full]]>
</Breakfast>
</Meals>
<HotelRoomPrices>
<HotelRoom Code="DB">
<RoomPrice Gross="1870.00"/>
<PriceRanges>
<PriceRange>
<DateRange>
<FromDate>2016-07-30</FromDate>
<ToDate>2016-08-02</ToDate>
</DateRange>
<Price Gross="467.50" Nights="4"/>
</PriceRange>
</PriceRanges>
</HotelRoom>
</HotelRoomPrices>
<ChargeConditions>
<ChargeCondition Type="cancellation">
<Condition Charge="true" ChargeAmount="1870.00" Currency="USD" FromDay="0" ToDay="0"/>
<Condition Charge="true" ChargeAmount="467.50" Currency="USD" FromDay="1" ToDay="2"/>
<Condition Charge="false" FromDay="3"/>
</ChargeCondition>
<ChargeCondition Type="amendment">
<Condition Charge="false" FromDay="0"/>
</ChargeCondition>
<PassengerNameChange Allowable="true"/>
</ChargeConditions>
</RoomCategory>
<RoomCategory Id="001:IBI3:17082:S16700:22530:91737">
<Description>
<![CDATA[Standard Triple]]>
</Description>
<ItemPrice CommissionPercentage="0.00" Currency="USD">2804.00</ItemPrice>
<Confirmation Code="IM">
<![CDATA[AVAILABLE]]>
</Confirmation>
<Meals>
<Basis Code="B">
<![CDATA[Breakfast]]>
</Basis>
<Breakfast Code="F">
<![CDATA[Full]]>
</Breakfast>
</Meals>
<HotelRoomPrices>
<HotelRoom Code="DB">
<RoomPrice Gross="2804.00"/>
<PriceRanges>
<PriceRange>
<DateRange>
<FromDate>2016-07-30</FromDate>
<ToDate>2016-08-02</ToDate>
</DateRange>
<Price Gross="701.00" Nights="4"/>
</PriceRange>
</PriceRanges>
</HotelRoom>
</HotelRoomPrices>
<ChargeConditions>
<ChargeCondition Type="cancellation">
<Condition Charge="true" ChargeAmount="2804.00" Currency="USD" FromDay="0" ToDay="0"/>
<Condition Charge="true" ChargeAmount="701.00" Currency="USD" FromDay="1" ToDay="2"/>
<Condition Charge="false" FromDay="3"/>
</ChargeCondition>
<ChargeCondition Type="amendment">
<Condition Charge="false" FromDay="0"/>
</ChargeCondition>
<PassengerNameChange Allowable="true"/>
</ChargeConditions>
</RoomCategory>
</RoomCategories>
</Hotel>
</HotelDetails>
</SearchHotelPriceResponse>
</ResponseDetails>
</Response>
And I the class I'm tring to deserialize this response to looks like this:
using System.Collections.Generic;
using System.Xml.Serialization;
namespace example
{
[XmlRoot(ElementName = "Response")]
public class GTASearchResponse
{
[XmlElement(ElementName = "Response")]
public Response response { get; set; }
}
[XmlRoot(ElementName = "City")]
public class City
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Item")]
public class Item
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Location")]
public class Location
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "LocationDetails")]
public class LocationDetails
{
[XmlElement(ElementName = "Location")]
public List<Location> Location { get; set; }
}
[XmlRoot(ElementName = "HotelRoom")]
public class HotelRoom
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlAttribute(AttributeName = "NumberOfRooms")]
public string NumberOfRooms { get; set; }
[XmlElement(ElementName = "RoomPrice")]
public RoomPrice RoomPrice { get; set; }
[XmlElement(ElementName = "PriceRanges")]
public PriceRanges PriceRanges { get; set; }
}
[XmlRoot(ElementName = "HotelRooms")]
public class HotelRooms
{
[XmlElement(ElementName = "HotelRoom")]
public HotelRoom HotelRoom { get; set; }
}
[XmlRoot(ElementName = "ItemPrice")]
public class ItemPrice
{
[XmlAttribute(AttributeName = "CommissionPercentage")]
public string CommissionPercentage { get; set; }
[XmlAttribute(AttributeName = "Currency")]
public string Currency { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Confirmation")]
public class Confirmation
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Basis")]
public class Basis
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Breakfast")]
public class Breakfast
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Meals")]
public class Meals
{
[XmlElement(ElementName = "Basis")]
public Basis Basis { get; set; }
[XmlElement(ElementName = "Breakfast")]
public Breakfast Breakfast { get; set; }
}
[XmlRoot(ElementName = "RoomPrice")]
public class RoomPrice
{
[XmlAttribute(AttributeName = "Gross")]
public string Gross { get; set; }
}
[XmlRoot(ElementName = "DateRange")]
public class DateRange
{
[XmlElement(ElementName = "FromDate")]
public string FromDate { get; set; }
[XmlElement(ElementName = "ToDate")]
public string ToDate { get; set; }
}
[XmlRoot(ElementName = "Price")]
public class Price
{
[XmlAttribute(AttributeName = "Gross")]
public string Gross { get; set; }
[XmlAttribute(AttributeName = "Nights")]
public string Nights { get; set; }
}
[XmlRoot(ElementName = "PriceRange")]
public class PriceRange
{
[XmlElement(ElementName = "DateRange")]
public DateRange DateRange { get; set; }
[XmlElement(ElementName = "Price")]
public Price Price { get; set; }
}
[XmlRoot(ElementName = "PriceRanges")]
public class PriceRanges
{
[XmlElement(ElementName = "PriceRange")]
public PriceRange PriceRange { get; set; }
}
[XmlRoot(ElementName = "HotelRoomPrices")]
public class HotelRoomPrices
{
[XmlElement(ElementName = "HotelRoom")]
public HotelRoom HotelRoom { get; set; }
}
[XmlRoot(ElementName = "Condition")]
public class Condition
{
[XmlAttribute(AttributeName = "Charge")]
public string Charge { get; set; }
[XmlAttribute(AttributeName = "ChargeAmount")]
public string ChargeAmount { get; set; }
[XmlAttribute(AttributeName = "Currency")]
public string Currency { get; set; }
[XmlAttribute(AttributeName = "FromDay")]
public string FromDay { get; set; }
[XmlAttribute(AttributeName = "ToDay")]
public string ToDay { get; set; }
}
[XmlRoot(ElementName = "ChargeCondition")]
public class ChargeCondition
{
[XmlElement(ElementName = "Condition")]
public List<Condition> Condition { get; set; }
[XmlAttribute(AttributeName = "Type")]
public string Type { get; set; }
}
[XmlRoot(ElementName = "PassengerNameChange")]
public class PassengerNameChange
{
[XmlAttribute(AttributeName = "Allowable")]
public string Allowable { get; set; }
}
[XmlRoot(ElementName = "ChargeConditions")]
public class ChargeConditions
{
[XmlElement(ElementName = "ChargeCondition")]
public List<ChargeCondition> ChargeCondition { get; set; }
[XmlElement(ElementName = "PassengerNameChange")]
public PassengerNameChange PassengerNameChange { get; set; }
}
[XmlRoot(ElementName = "RoomCategory")]
public class RoomCategory
{
[XmlElement(ElementName = "Description")]
public string Description { get; set; }
[XmlElement(ElementName = "ItemPrice")]
public ItemPrice ItemPrice { get; set; }
[XmlElement(ElementName = "Confirmation")]
public Confirmation Confirmation { get; set; }
[XmlElement(ElementName = "Meals")]
public Meals Meals { get; set; }
[XmlElement(ElementName = "HotelRoomPrices")]
public HotelRoomPrices HotelRoomPrices { get; set; }
[XmlElement(ElementName = "ChargeConditions")]
public ChargeConditions ChargeConditions { get; set; }
[XmlAttribute(AttributeName = "Id")]
public string Id { get; set; }
}
[XmlRoot(ElementName = "RoomCategories")]
public class RoomCategories
{
[XmlElement(ElementName = "RoomCategory")]
public List<RoomCategory> RoomCategory { get; set; }
}
[XmlRoot(ElementName = "Hotel")]
public class Hotel
{
[XmlElement(ElementName = "City")]
public City City { get; set; }
[XmlElement(ElementName = "Item")]
public Item Item { get; set; }
[XmlElement(ElementName = "LocationDetails")]
public LocationDetails LocationDetails { get; set; }
[XmlElement(ElementName = "StarRating")]
public string StarRating { get; set; }
[XmlElement(ElementName = "HotelRooms")]
public HotelRooms HotelRooms { get; set; }
[XmlElement(ElementName = "RoomCategories")]
public RoomCategories RoomCategories { get; set; }
[XmlAttribute(AttributeName = "HasExtraInfo")]
public string HasExtraInfo { get; set; }
[XmlAttribute(AttributeName = "HasMap")]
public string HasMap { get; set; }
[XmlAttribute(AttributeName = "HasPictures")]
public string HasPictures { get; set; }
}
[XmlRoot(ElementName = "HotelDetails")]
public class HotelDetails
{
[XmlElement(ElementName = "Hotel")]
public Hotel Hotel { get; set; }
}
[XmlRoot(ElementName = "SearchHotelPriceResponse")]
public class SearchHotelPriceResponse
{
[XmlElement(ElementName = "HotelDetails")]
public HotelDetails HotelDetails { get; set; }
}
[XmlRoot(ElementName = "ResponseDetails")]
public class ResponseDetails
{
[XmlElement(ElementName = "SearchHotelPriceResponse")]
public SearchHotelPriceResponse SearchHotelPriceResponse { get; set; }
[XmlAttribute(AttributeName = "Language")]
public string Language { get; set; }
}
[XmlRoot(ElementName = "Response")]
public class Response
{
[XmlElement(ElementName = "ResponseDetails")]
public ResponseDetails ResponseDetails { get; set; }
[XmlAttribute(AttributeName = "ResponseReference")]
public string ResponseReference { get; set; }
}
}
unfortunately when I deserialize I get a null value for a child element of the response property, visual studio looks like this when I debug:
You can see if i put a watch on the variable answer then I only get back a null Response class. Help?
From the Xml Attributes on GTASearchResponse it looks like you are expecting a schema
<response><response> ...
because there is the root and the attribute response. I think if you just deserialize your content directly to "Response" type it might work
Related
Trying to Deserialise XML response to C#. but getting error as specified below.
My code:
IRestResponse result = Client.Execute<StudentPersonal>(new RestRequest(Method.POST)
.AddHeader("Accept", " application/xml")
.AddHeader("Authorization", "Basic Y2xaTWNqZFFlbFF4YVU1TlFtUnZOV3hXTkhadmNHaFhPSGxTT0Rka1VIcFhhRTl5TWtWQ05rRjNUMlp5VlUxWlNYa3hjbEU1V1RGUmMxTkNOMlZWVlRvNk9nPT06eUkxdERIanNVcGxLUUpzUlNXNTVacXpRVUFGQ3JrZzFwUGxUbDhUTmRQaFU0Z0xsTFJlQkVxTmhzZml3TnpaVA==")
.AddHeader("Content-Type", "application/xml")
.AddParameter("application/xml", body, ParameterType.RequestBody));
StudentPersonal firstResponse = new StudentPersonal();
StringReader srt = new StringReader(result.Content);
XmlSerializer serializer = new XmlSerializer(typeof(StudentPersonal), new XmlRootAttribute("StudentPersonal"));
firstResponse = (StudentPersonal)serializer.Deserialize(srt);
Console.WriteLine(firstResponse);
Assert.AreEqual("Created", result.StatusCode.ToString());
My classes:
[XmlRoot(ElementName = "StudentPersonal")]
public class StudentPersonal
{
//// XmlSerializer serializer = new XmlSerializer(typeof(StudentPersonal));
//// using (StringReader reader = new StringReader(xml))
//// {
//// var test = (StudentPersonal)serializer.Deserialize(reader);
//// }
[XmlElement(ElementName = "LocalId")]
public double LocalId { get; set; }
[XmlElement(ElementName = "StateProvinceId")]
public int StateProvinceId { get; set; }
[XmlElement(ElementName = "ElectronicIdList")]
public object ElectronicIdList { get; set; }
[XmlElement(ElementName = "OtherIdList")]
public OtherIdList OtherIdList { get; set; }
[XmlElement(ElementName = "PersonInfo")]
public PersonInfo PersonInfo { get; set; }
[XmlElement(ElementName = "GiftedTalented")]
public string GiftedTalented { get; set; }
[XmlElement(ElementName = "EconomicDisadvantage")]
public string EconomicDisadvantage { get; set; }
[XmlElement(ElementName = "ESL")]
public string ESL { get; set; }
[XmlElement(ElementName = "YoungCarersRole")]
public string YoungCarersRole { get; set; }
[XmlElement(ElementName = "Disability")]
public string Disability { get; set; }
[XmlElement(ElementName = "IntegrationAide")]
public string IntegrationAide { get; set; }
[XmlElement(ElementName = "EducationSupport")]
public string EducationSupport { get; set; }
[XmlElement(ElementName = "Sensitive")]
public string Sensitive { get; set; }
[XmlAttribute(AttributeName = "xsd")]
public string Xsd { get; set; }
[XmlAttribute(AttributeName = "xsi")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "RefId")]
public string RefId { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "OtherId")]
public class OtherId
{
[XmlAttribute(AttributeName = "Type")]
public string Type { get; set; }
[XmlText]
public int Text { get; set; }
}
[XmlRoot(ElementName = "OtherIdList")]
public class OtherIdList
{
[XmlElement(ElementName = "OtherId")]
public List<OtherId> OtherId { get; set; }
}
[XmlRoot(ElementName = "Name")]
public class Name
{
[XmlElement(ElementName = "Title")]
public string Title { get; set; }
[XmlElement(ElementName = "FamilyName")]
public string FamilyName { get; set; }
[XmlElement(ElementName = "GivenName")]
public string GivenName { get; set; }
[XmlElement(ElementName = "MiddleName")]
public string MiddleName { get; set; }
[XmlElement(ElementName = "FamilyNameFirst")]
public string FamilyNameFirst { get; set; }
[XmlElement(ElementName = "PreferredFamilyName")]
public string PreferredFamilyName { get; set; }
[XmlElement(ElementName = "PreferredFamilyNameFirst")]
public string PreferredFamilyNameFirst { get; set; }
[XmlElement(ElementName = "PreferredGivenName")]
public string PreferredGivenName { get; set; }
[XmlElement(ElementName = "FullName")]
public string FullName { get; set; }
[XmlAttribute(AttributeName = "Type")]
public string Type { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "EnglishProficiency")]
public class EnglishProficiency
{
[XmlElement(ElementName = "Code")]
public int Code { get; set; }
}
[XmlRoot(ElementName = "Language")]
public class Language
{
[XmlElement(ElementName = "Code")]
public int Code { get; set; }
[XmlElement(ElementName = "LanguageType")]
public int LanguageType { get; set; }
}
[XmlRoot(ElementName = "LanguageList")]
public class LanguageList
{
[XmlElement(ElementName = "Language")]
public List<Language> Language { get; set; }
}
[XmlRoot(ElementName = "DwellingArrangement")]
public class DwellingArrangement
{
[XmlElement(ElementName = "Code")]
public int Code { get; set; }
}
[XmlRoot(ElementName = "Religion")]
public class Religion
{
[XmlElement(ElementName = "Code")]
public int Code { get; set; }
}
[XmlRoot(ElementName = "ReligiousEvent")]
public class ReligiousEvent
{
[XmlElement(ElementName = "Type")]
public string Type { get; set; }
[XmlElement(ElementName = "Date")]
public DateTime Date { get; set; }
}
[XmlRoot(ElementName = "ReligiousEventList")]
public class ReligiousEventList
{
[XmlElement(ElementName = "ReligiousEvent")]
public ReligiousEvent ReligiousEvent { get; set; }
}
[XmlRoot(ElementName = "Demographics")]
public class Demographics
{
[XmlElement(ElementName = "IndigenousStatus")]
public int IndigenousStatus { get; set; }
[XmlElement(ElementName = "Sex")]
public int Sex { get; set; }
[XmlElement(ElementName = "BirthDate")]
public DateTime BirthDate { get; set; }
[XmlElement(ElementName = "BirthDateVerification")]
public int BirthDateVerification { get; set; }
[XmlElement(ElementName = "CountryArrivalDate")]
public DateTime CountryArrivalDate { get; set; }
[XmlElement(ElementName = "EnglishProficiency")]
public EnglishProficiency EnglishProficiency { get; set; }
[XmlElement(ElementName = "LanguageList")]
public LanguageList LanguageList { get; set; }
[XmlElement(ElementName = "DwellingArrangement")]
public DwellingArrangement DwellingArrangement { get; set; }
[XmlElement(ElementName = "Religion")]
public Religion Religion { get; set; }
[XmlElement(ElementName = "ReligiousEventList")]
public ReligiousEventList ReligiousEventList { get; set; }
[XmlElement(ElementName = "PermanentResident")]
public string PermanentResident { get; set; }
[XmlElement(ElementName = "VisaSubClass")]
public int VisaSubClass { get; set; }
[XmlElement(ElementName = "VisaStatisticalCode")]
public string VisaStatisticalCode { get; set; }
[XmlElement(ElementName = "VisaExpiryDate")]
public DateTime VisaExpiryDate { get; set; }
[XmlElement(ElementName = "LBOTE")]
public string LBOTE { get; set; }
[XmlElement(ElementName = "ImmunisationCertificateStatus")]
public string ImmunisationCertificateStatus { get; set; }
[XmlElement(ElementName = "CulturalBackground")]
public int CulturalBackground { get; set; }
[XmlElement(ElementName = "MaritalStatus")]
public int MaritalStatus { get; set; }
[XmlElement(ElementName = "MedicareNumber")]
public int MedicareNumber { get; set; }
}
[XmlRoot(ElementName = "PhoneNumber")]
public class PhoneNumber
{
[XmlElement(ElementName = "Number")]
public int Number { get; set; }
[XmlElement(ElementName = "ListedStatus")]
public string ListedStatus { get; set; }
[XmlAttribute(AttributeName = "Type")]
public int Type { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "PhoneNumberList")]
public class PhoneNumberList
{
[XmlElement(ElementName = "PhoneNumber")]
public PhoneNumber PhoneNumber { get; set; }
}
[XmlRoot(ElementName = "Email")]
public class Email
{
[XmlAttribute(AttributeName = "Type")]
public int Type { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "EmailList")]
public class EmailList
{
[XmlElement(ElementName = "Email")]
public List<Email> Email { get; set; }
}
[XmlRoot(ElementName = "PersonInfo")]
public class PersonInfo
{
[XmlElement(ElementName = "Name")]
public Name Name { get; set; }
[XmlElement(ElementName = "Demographics")]
public Demographics Demographics { get; set; }
[XmlElement(ElementName = "AddressList")]
public object AddressList { get; set; }
[XmlElement(ElementName = "PhoneNumberList")]
public PhoneNumberList PhoneNumberList { get; set; }
[XmlElement(ElementName = "EmailList")]
public EmailList EmailList { get; set; }
}
Below is the response XML details from Result.content:
<StudentPersonal xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" RefId=\"9ec476fd-09b5-4b2b-967a-fb80b207526e\" xmlns=\"http://www.sifassociation.org/datamodel/au/3.4\">
<LocalId>2432717276450097998</LocalId>
<StateProvinceId>674361</StateProvinceId>
<ElectronicIdList />
<OtherIdList>
<OtherId Type=\"MazeKey\">674363</OtherId>
<OtherId Type=\"VETUSI\">674362</OtherId>
<OtherId Type=\"UPN\">674363</OtherId>
</OtherIdList>
<PersonInfo>
<Name Type=\"LGL\">
<Title>Ms</Title>
<FamilyName>Gutteridge2</FamilyName>
<GivenName>Ferdinanda2</GivenName>
<MiddleName>Creamer1</MiddleName>
<FamilyNameFirst>N</FamilyNameFirst>
<PreferredFamilyName>Gutteridge</PreferredFamilyName>
<PreferredFamilyNameFirst>N</PreferredFamilyNameFirst>
<PreferredGivenName>Ferdinanda</PreferredGivenName>
<FullName> Ferdinanda Gutteridge</FullName>
</Name>
<Demographics>
<IndigenousStatus>1</IndigenousStatus>
<Sex>2</Sex>
<BirthDate>2006-03-21</BirthDate>
<BirthDateVerification>1004</BirthDateVerification>
<CountryArrivalDate>2008-09-17</CountryArrivalDate>
<EnglishProficiency>
<Code>1</Code>
</EnglishProficiency>
<LanguageList>
<Language>
<Code>1201</Code>
<LanguageType>3</LanguageType>
</Language>
<Language>
<Code>4303</Code>
<LanguageType>1</LanguageType>
</Language>
<Language>
<Code>4303</Code>
<LanguageType>1</LanguageType>
</Language>
</LanguageList>
<DwellingArrangement>
<Code>1671</Code>
</DwellingArrangement>
<Religion>
<Code>0002</Code>
</Religion>
<ReligiousEventList>
<ReligiousEvent>
<Type>Confirmation</Type>
<Date>2018-07-17</Date>
</ReligiousEvent>
</ReligiousEventList>
<PermanentResident>P</PermanentResident>
<VisaSubClass>124</VisaSubClass>
<VisaStatisticalCode>VisaStatisticalCode</VisaStatisticalCode>
<VisaExpiryDate>2019-01-17</VisaExpiryDate>
<LBOTE>N</LBOTE>
<ImmunisationCertificateStatus>C</ImmunisationCertificateStatus>
<CulturalBackground>0901</CulturalBackground>
<MaritalStatus>3</MaritalStatus>
<MedicareNumber>67436</MedicareNumber>
</Demographics>
<AddressList />
<PhoneNumberList>
<PhoneNumber Type=\"0350\">
<Number>12367436</Number>
<ListedStatus>U</ListedStatus>
</PhoneNumber>
</PhoneNumberList>
<EmailList>
<Email Type=\"01\">person67436#email1.com.au</Email>
<Email Type=\"02\">person67436#email2.com.au</Email>
<Email Type=\"03\">person67436#email3.com.au</Email>
</EmailList>
</PersonInfo>
<GiftedTalented>N</GiftedTalented>
<EconomicDisadvantage>N</EconomicDisadvantage>
<ESL>N</ESL>
<YoungCarersRole>N</YoungCarersRole>
<Disability>N</Disability>
<IntegrationAide>N</IntegrationAide>
<EducationSupport>U</EducationSupport>
<Sensitive>N</Sensitive>
</StudentPersonal>
Error is from the above XML response. Getting Error
There is an error in XML document (1, 2). InvalidOperationException: <StudentPersonal xmlns='http://www.sifassociation.org/datamodel/au/3.4'> was not expected.
There seems to be two issues.
Add the namespace to your class:
[XmlRoot(ElementName = "StudentPersonal", Namespace = "http://www.sifassociation.org/datamodel/au/3.4")]
public class StudentPersonal
...
In the XML, all " are escaped with \.
<StudentPersonal xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" RefId=\"9ec476fd-09b5-4b2b-967a-fb80b207526e\" xmlns=\"http://www.sifassociation.org/datamodel/au/3.4\">
...
</StudentPersonal>
This also occurs in other places throughout the XML. Such as:
<PhoneNumber Type=\"0350\">
To resolve the issue, replace all occurrences of \" with ".
<StudentPersonal xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RefId="9ec476fd-09b5-4b2b-967a-fb80b207526e" xmlns="http://www.sifassociation.org/datamodel/au/3.4">
...
</StudentPersonal>
and
<PhoneNumber Type="0350">
Here's a method that can be used to deserialize the XML:
DeserializeXMLStringToObject:
public static T DeserializeXMLStringToObject<T>(string xmlData)
{
T rObject = default(T);
try
{
if (string.IsNullOrEmpty(xmlData))
{
return default(T);
}
//replace \" with "
string xmlDataSanitized = xmlData.Replace("\\\"", "\"");
using (System.IO.StringReader reader = new System.IO.StringReader(xmlDataSanitized))
{
//add the namespace to the class instead of adding it here
//System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T), "http://www.sifassociation.org/datamodel/au/3.4");
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
rObject = (T)serializer.Deserialize(reader);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
throw ex;
}
return rObject;
}
Usage:
private StudentPersonal _studentPersonal = null;
...
_studentPersonal = DeserializeXMLStringToObject<StudentPersonal>(result.Content);
//for testing, display some of the data
//System.Diagnostics.Debug.WriteLine("LocalId: " + _studentPersonal.LocalId);
//System.Diagnostics.Debug.WriteLine("GivenName: " + _studentPersonal.PersonInfo.Name.GivenName);
I have the following xml file which I have tried to load using method to turn it into a business object however it says expecting > at line 1 ,40 but when I look at it looks fine.
XmlSerializer serializer = new XmlSerializer(typeof( SalesOrderXml));
using (TextReader reader = new StringReader(testData))
{
SalesOrderXmlresult = (SalesOrderXml) serializer.Deserialize(reader);
}
Xml here cause of the length of it it would have exceeded the article.
https://pastebin.com/pepp1QDe
I do not no what i am doing wrong as I used the online xml to poco generator to help me out as a its a long file.
Any tips of what i might be doing wrong I checked for hidden chars in the file and there is none.
public class SalesOrderXml
{
[XmlRoot(ElementName = "ORDER_ITEM")]
public class ORDER_ITEM
{
[XmlElement(ElementName = "PRODUCT_ID")]
public string PRODUCT_ID { get; set; }
[XmlElement(ElementName = "STOCK_CODE")]
public string STOCK_CODE { get; set; }
[XmlElement(ElementName = "ITEM_TYPE")]
public string ITEM_TYPE { get; set; }
[XmlElement(ElementName = "DESCRIPTION")]
public string DESCRIPTION { get; set; }
[XmlElement(ElementName = "QUANTITY")]
public string QUANTITY { get; set; }
[XmlElement(ElementName = "PRICE")]
public string PRICE { get; set; }
[XmlElement(ElementName = "HEIGHT")]
public string HEIGHT { get; set; }
[XmlElement(ElementName = "WIDTH")]
public string WIDTH { get; set; }
[XmlElement(ElementName = "HINGE_HOLES")]
public string HINGE_HOLES { get; set; }
[XmlElement(ElementName = "DRILL_TOP")]
public string DRILL_TOP { get; set; }
[XmlElement(ElementName = "DRILL_BOTTOM")]
public string DRILL_BOTTOM { get; set; }
[XmlElement(ElementName = "DRILL_TOP_1")]
public string DRILL_TOP_1 { get; set; }
[XmlElement(ElementName = "DRILL_TOP_2")]
public string DRILL_TOP_2 { get; set; }
[XmlElement(ElementName = "DRILL_TOP_3")]
public string DRILL_TOP_3 { get; set; }
[XmlElement(ElementName = "RAW")]
public string RAW { get; set; }
[XmlElement(ElementName = "RAH")]
public string RAH { get; set; }
[XmlElement(ElementName = "LAW")]
public string LAW { get; set; }
[XmlElement(ElementName = "LAH")]
public string LAH { get; set; }
[XmlElement(ElementName = "FRAME_TYPE")]
public string FRAME_TYPE { get; set; }
[XmlElement(ElementName = "GLAZING_TYPE")]
public string GLAZING_TYPE { get; set; }
[XmlElement(ElementName = "LENGTH")]
public string LENGTH { get; set; }
[XmlElement(ElementName = "DEPTH")]
public string DEPTH { get; set; }
[XmlElement(ElementName = "CORNER_POSITION")]
public string CORNER_POSITION { get; set; }
[XmlElement(ElementName = "HORIZONTAL_GRAIN")]
public string HORIZONTAL_GRAIN { get; set; }
[XmlElement(ElementName = "PANEL_TYPE")]
public string PANEL_TYPE { get; set; }
[XmlElement(ElementName = "PANEL_EDGE")]
public string PANEL_EDGE { get; set; }
[XmlElement(ElementName = "PROFILED_EDGE")]
public string PROFILED_EDGE { get; set; }
[XmlElement(ElementName = "PROFILED_EDGE_FRONT")]
public string PROFILED_EDGE_FRONT { get; set; }
[XmlElement(ElementName = "PROFILED_EDGE_BACK")]
public string PROFILED_EDGE_BACK { get; set; }
[XmlElement(ElementName = "PROFILED_EDGE_LEFT")]
public string PROFILED_EDGE_LEFT { get; set; }
[XmlElement(ElementName = "PROFILED_EDGE_RIGHT")]
public string PROFILED_EDGE_RIGHT { get; set; }
[XmlElement(ElementName = "EDGE_TYPE")]
public string EDGE_TYPE { get; set; }
[XmlElement(ElementName = "ANGLES_REQUIRED")]
public string ANGLES_REQUIRED { get; set; }
[XmlElement(ElementName = "ANGLE_LENGTH")]
public string ANGLE_LENGTH { get; set; }
[XmlElement(ElementName = "ANGLE_DEPTH")]
public string ANGLE_DEPTH { get; set; }
[XmlElement(ElementName = "THICKNESS")]
public string THICKNESS { get; set; }
[XmlElement(ElementName = "REVERSE_COLOUR")]
public string REVERSE_COLOUR { get; set; }
}
[XmlRoot(ElementName = "DELIVERY_ADDRESS")]
public class DELIVERY_ADDRESS
{
[XmlElement(ElementName = "ADDRESS1")]
public string ADDRESS1 { get; set; }
[XmlElement(ElementName = "ADDRESS2")]
public string ADDRESS2 { get; set; }
[XmlElement(ElementName = "TOWN")]
public string TOWN { get; set; }
[XmlElement(ElementName = "POSTCODE")]
public string POSTCODE { get; set; }
[XmlElement(ElementName = "COUNTY")]
public string COUNTY { get; set; }
[XmlElement(ElementName = "COUNTRY")]
public string COUNTRY { get; set; }
}
[XmlRoot(ElementName = "ORDER")]
public class ORDER
{
[XmlElement(ElementName = "ORDER_ID")]
public string ORDER_ID { get; set; }
[XmlElement(ElementName = "ORDERED_BY")]
public string ORDERED_BY { get; set; }
[XmlElement(ElementName = "ORDER_REFERENCE")]
public string ORDER_REFERENCE { get; set; }
[XmlElement(ElementName = "CUSTOMER_ID")]
public string CUSTOMER_ID { get; set; }
[XmlElement(ElementName = "ACCOUNT_REFERENCE")]
public string ACCOUNT_REFERENCE { get; set; }
[XmlElement(ElementName = "ORDER_TYPE")]
public string ORDER_TYPE { get; set; }
[XmlElement(ElementName = "ORDER_RANGE")]
public string ORDER_RANGE { get; set; }
[XmlElement(ElementName = "ORDER_COLOUR")]
public string ORDER_COLOUR { get; set; }
[XmlElement(ElementName = "EDGE_TYPE")]
public string EDGE_TYPE { get; set; }
[XmlElement(ElementName = "REVERSE_COLOUR")]
public string REVERSE_COLOUR { get; set; }
[XmlElement(ElementName = "HORIZONTAL_GRAIN")]
public string HORIZONTAL_GRAIN { get; set; }
[XmlElement(ElementName = "HANDLE_TYPE")]
public string HANDLE_TYPE { get; set; }
[XmlElement(ElementName = "NOTES")]
public string NOTES { get; set; }
[XmlElement(ElementName = "ORDER_DATE")]
public string ORDER_DATE { get; set; }
[XmlElement(ElementName = "DELIVERY_DATE")]
public string DELIVERY_DATE { get; set; }
[XmlElement(ElementName = "ADDITIONAL_DELIVERY_INFO")]
public string ADDITIONAL_DELIVERY_INFO { get; set; }
[XmlElement(ElementName = "ORDER_ITEM")]
public List<ORDER_ITEM> ORDER_ITEM { get; set; }
[XmlElement(ElementName = "DELIVERY_ADDRESS")]
public DELIVERY_ADDRESS DELIVERY_ADDRESS { get; set; }
[XmlElement(ElementName = "DELIVERY_TYPE")]
public string DELIVERY_TYPE { get; set; }
[XmlElement(ElementName = "DELIVERY_PRICE")]
public string DELIVERY_PRICE { get; set; }
[XmlElement(ElementName = "DELIVERY_CODE")]
public string DELIVERY_CODE { get; set; }
[XmlElement(ElementName = "TOTAL_EX_VAT")]
public string TOTAL_EX_VAT { get; set; }
[XmlElement(ElementName = "TOTAL_INC_VAT")]
public string TOTAL_INC_VAT { get; set; }
[XmlElement(ElementName = "TOTAL_INC_DELIVERY")]
public string TOTAL_INC_DELIVERY { get; set; }
}
}
Although I didn't get the same error as you when I setup a test case using your code, I did get an error about "ORDER" being unexpected.
I then successfully deserialized the XML by specifying SalesOrderXml.ORDER as the root class, rather than SalesOrderXml.
XmlSerializer serializer = new XmlSerializer(typeof(SalesOrderXml.ORDER));
using (TextReader reader = new StringReader(testData))
{
var ob = (SalesOrderXml.ORDER)serializer.Deserialize(reader);
}
I set testData exactly the same as your pastebin string (with the spaces trimmed as per Renzo's comment), and my test case ran successfully.
I am retrieving xml data from an web api and deserializing the data into objects.:
<Result>
<VendorInfo xml:lang="xx">
<Vendor vname="A" cpe="B">
<Product pname="C" cpe="D"/>
</Vendor>
<Vendor vname="E" cpe="F">
<Product pname="G" cpe="H"/>
</Vendor>
<Vendor vname="I" cpe="J">
<Product pname="K" cpe="L"/>
<Product pname="M" cpe="N"/>
</Vendor>
</VendorInfo>
<Status keyword="hoge" feed="bar"/>
</Result>
My current code is this:
[XmlRoot(ElementName = "Product")]
public class Product
{
[XmlAttribute(AttributeName = "pname")]
public string Pname { get; set; }
[XmlAttribute(AttributeName = "cpe")]
public string Cpe { get; set; }
}
[XmlRoot(ElementName = "Vendor")]
public class Vendor
{
[XmlArrayItem(ElementName = "Product")]
public List<Product> Product { get; set; }
[XmlAttribute(AttributeName = "vname")]
public string Vname { get; set; }
[XmlAttribute(AttributeName = "cpe")]
public string Cpe { get; set; }
}
[XmlRoot(ElementName = "VendorInfo")]
public class VendorInfo
{
[XmlElement(ElementName = "Vendor")]
public List<Vendor> Vendor { get; set; }
[XmlAttribute(AttributeName = "lang")]
public string Lang { get; set; }
}
[XmlRoot(ElementName = "Status")]
public class Status
{
[XmlAttribute(AttributeName = "feed")]
public string Feed { get; set; }
[XmlAttribute(AttributeName = "keyword")]
public string Keyword { get; set; }
}
[XmlRoot(ElementName = "Result")]
public class Result
{
[XmlElement(ElementName = "VendorInfo")]
public VendorInfo VendorInfo { get; set; }
[XmlElement(ElementName = "Status")]
public Status Status { get; set; }
}
But, This code does not working correctly.
Only first 2 Vendor elements are deserialized, Product element is not deserialized.
What am i doing wrong?
best regards
You have few things to be taken care.
Make only one element XmlRoot. Refer below link and search for "Controlling Serialization of Classes Using XmlRootAttribute and XmlTypeAttribute".
https://learn.microsoft.com/en-us/dotnet/standard/serialization/controlling-xml-serialization-using-attributes
Here in your case, the "Result" class is root.
Make rest all XmlType.
In the vendor class instead of "XmlArrayItem", make it just "XmlElement".
Here is the working code.
[XmlType("Product")]
public class Product
{
[XmlAttribute(AttributeName = "pname")]
public string Pname { get; set; }
[XmlAttribute(AttributeName = "cpe")]
public string Cpe { get; set; }
}
[XmlType("Vendor")]
public class Vendor
{
[XmlElement(ElementName = "Product")]
public List<Product> Product { get; set; }
[XmlAttribute(AttributeName = "vname")]
public string Vname { get; set; }
[XmlAttribute(AttributeName = "cpe")]
public string Cpe { get; set; }
}
[XmlType("VendorInfo")]
public class VendorInfo
{
[XmlElement(ElementName = "Vendor")]
public List<Vendor> Vendor { get; set; }
[XmlAttribute(AttributeName = "xml:lang")]
public string Lang { get; set; }
}
[XmlType("Status")]
public class Status
{
[XmlAttribute(AttributeName = "feed")]
public string Feed { get; set; }
[XmlAttribute(AttributeName = "keyword")]
public string Keyword { get; set; }
}
[XmlRoot(ElementName = "Result")]
public class Result
{
[XmlElement(ElementName = "VendorInfo")]
public VendorInfo VendorInfo { get; set; }
[XmlElement(ElementName = "Status")]
public Status Status { get; set; }
}
I would like to deserializing xsi:nil="true"
I have this in my XML that I want to deserialize
<Sekretessmarkering xsi:nil="true" />
I'm guessing it's a boolean (true or false).
I know how to deserialize normal string values on the XML. I have this that works:
My deserialize class:
[XmlRoot(ElementName = "Sekretessmarkering")]
public class Sekretessmarkering
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public bool Nil { get; set; }
}
[XmlRoot(ElementName = "PersonId")]
public class PersonId
{
[XmlElement(ElementName = "PersonNr")]
public string PersonNr { get; set; }
[XmlElement(ElementName = "TilldelatPersonNrSamordningsNr")]
public string Tilltalsnamnsmarkering { get; set; }
}
[XmlRoot(ElementName = "Avregistrering")]
public class Avregistrering
{
[XmlElement(ElementName = "AvregistreringsorsakKod")]
public string AvregistreringsorsakKod { get; set; }
[XmlElement(ElementName = "Avregistreringsdatum")]
public string Avregistreringsdatum { get; set; }
}
[XmlRoot(ElementName = "HanvisningsPersonNr")]
public class HanvisningsPersonNr
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Mellannamn")]
public class Mellannamn
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Aviseringsnamn")]
public class Aviseringsnamn
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Namn")]
public class Namn
{
[XmlElement(ElementName = "Tilltalsnamnsmarkering")]
public string Tilltalsnamnsmarkering { get; set; }
[XmlElement(ElementName = "Fornamn")]
public string Fornamn { get; set; }
[XmlElement(ElementName = "Mellannamn")]
public Mellannamn Mellannamn { get; set; }
[XmlElement(ElementName = "Efternamn")]
public string Efternamn { get; set; }
[XmlElement(ElementName = "Aviseringsnamn")]
public Aviseringsnamn Aviseringsnamn { get; set; }
}
[XmlRoot(ElementName = "ForsamlingKod")]
public class ForsamlingKod
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Folkbokforing")]
public class Folkbokforing
{
[XmlElement(ElementName = "Folkbokforingsdatum")]
public string Folkbokforingsdatum { get; set; }
[XmlElement(ElementName = "LanKod")]
public string LanKod { get; set; }
[XmlElement(ElementName = "KommunKod")]
public string KommunKod { get; set; }
[XmlElement(ElementName = "ForsamlingKod")]
public ForsamlingKod ForsamlingKod { get; set; }
[XmlElement(ElementName = "Fastighetsbeteckning")]
public string Fastighetsbeteckning { get; set; }
[XmlElement(ElementName = "FiktivtNr")]
public string FiktivtNr { get; set; }
}
[XmlRoot(ElementName = "CareOf")]
public class CareOf
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Utdelningsadress1")]
public class Utdelningsadress1
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
}
[XmlRoot(ElementName = "Folkbokforingsadress")]
public class Folkbokforingsadress
{
[XmlElement(ElementName = "CareOf")]
public CareOf CareOf { get; set; }
[XmlElement(ElementName = "Utdelningsadress1")]
public string Utdelningsadress1 { get; set; }
[XmlElement(ElementName = "Utdelningsadress2")]
public string Utdelningsadress2 { get; set; }
[XmlElement(ElementName = "PostNr")]
public string PostNr { get; set; }
[XmlElement(ElementName = "Postort")]
public string Postort { get; set; }
}
[XmlRoot(ElementName = "Utlandsadress")]
public class Utlandsadress
{
[XmlElement(ElementName = "Utdelningsadress1")]
public string Utdelningsadress1 { get; set; }
[XmlElement(ElementName = "Utdelningsadress2")]
public string Utdelningsadress2 { get; set; }
[XmlElement(ElementName = "Utdelningsadress3")]
public string Utdelningsadress3 { get; set; }
}
[XmlRoot(ElementName = "Riksnycklar")]
public class Riksnycklar
{
[XmlElement(ElementName = "FastighetsId")]
public string FastighetsId { get; set; }
[XmlElement(ElementName = "AdressplatsId")]
public string AdressplatsId { get; set; }
[XmlElement(ElementName = "LagenhetsId")]
public string LagenhetsId { get; set; }
}
[XmlRoot(ElementName = "Adresser")]
public class Adresser
{
[XmlElement(ElementName = "Utlandsadress")]
public Utlandsadress Utlandsadress { get; set; }
[XmlElement(ElementName = "Folkbokforingsadress")]
public Folkbokforingsadress Folkbokforingsadress { get; set; }
[XmlElement(ElementName = "Riksnycklar")]
public Riksnycklar Riksnycklar { get; set; }
}
[XmlRoot(ElementName = "HemortSverige")]
public class HemortSverige
{
[XmlElement(ElementName = "FodelselanKod")]
public string FodelselanKod { get; set; }
[XmlElement(ElementName = "Fodelseforsamling")]
public string Fodelseforsamling { get; set; }
}
[XmlRoot(ElementName = "OrtUtlandet")]
public class OrtUtlandet
{
[XmlElement(ElementName = "FodelseortUtland")]
public string FodelseortUtland { get; set; }
}
[XmlRoot(ElementName = "Fodelse")]
public class Fodelse
{
[XmlElement(ElementName = "HemortSverige")]
public HemortSverige HemortSverige { get; set; }
[XmlElement(ElementName = "OrtUtlandet")]
public OrtUtlandet OrtUtlandet { get; set; }
}
[XmlRoot(ElementName = "Medborgarskap")]
public class Medborgarskap
{
[XmlElement(ElementName = "MedborgarskapslandKod")]
public string MedborgarskapslandKod { get; set; }
[XmlElement(ElementName = "Medborgarskapsdatum")]
public string Medborgarskapsdatum { get; set; }
}
[XmlRoot(ElementName = "Personpost")]
public class Personpost
{
[XmlElement(ElementName = "PersonId")]
public PersonId PersonId { get; set; }
[XmlElement(ElementName = "Avregistrering")]
public Avregistrering Avregistrering { get; set; }
[XmlElement(ElementName = "HanvisningsPersonNr")]
public HanvisningsPersonNr HanvisningsPersonNr { get; set; }
[XmlElement(ElementName = "Namn")]
public Namn Namn { get; set; }
[XmlElement(ElementName = "Folkbokforing")]
public Folkbokforing Folkbokforing { get; set; }
[XmlElement(ElementName = "Adresser")]
public Adresser Adresser { get; set; }
[XmlElement(ElementName = "Fodelse")]
public Fodelse Fodelse { get; set; }
[XmlElement(ElementName = "Medborgarskap")]
public Medborgarskap Medborgarskap { get; set; }
}
[XmlRoot(ElementName = "FolkbokforingspostTYPE")]
public class FolkbokforingspostTYPE
{
[XmlElement(ElementName = "Sekretessmarkering")]
public string Sekretessmarkering { get; set; }
[XmlElement(ElementName = "Personpost")]
public Personpost Personpost { get; set; }
}
}
List<FolkbokforingspostTYPE> deserializedList = new List<FolkbokforingspostTYPE>();
deserializedList = Deserialize<List<FolkbokforingspostTYPE>>();
var myPersons = Deserialize<List<FolkbokforingspostTYPE>>()
.Select(x => new Person
{
PersonalIdentityNumber = x.Personpost.PersonId.PersonNr,
SpecialIdentityNumber = x.Personpost.PersonId.Tilltalsnamnsmarkering != null ? x.Personpost.PersonId.Tilltalsnamnsmarkering : null,
LastName = x.Personpost.Namn.Efternamn,
FirstName = x.Personpost.Namn.Fornamn,
NationalRegistrationCountyCode = x.Personpost.Folkbokforing.LanKod,
NationalRegistrationMunicipalityCode = x.Personpost.Folkbokforing.KommunKod,
ForeignDistrubtionAddress1 = x.Personpost.Adresser.Utlandsadress != null ? x.Personpost.Adresser.Utlandsadress.Utdelningsadress1 : null,
});
How can I deserialize <Sekretessmarkering xsi:nil="true" /> in the same way?
I'm trying to parse XML to c# object with XmlSerializer:
XmlSerializer serialize = new XmlSerializer(typeof(Xml2CSharp.LowFareSearchCorpRsp));
StringReader rdr = new StringReader(tmpRes);
Xml2CSharp.LowFareSearchCorpRsp res = (Xml2CSharp.LowFareSearchCorpRsp)serializer.Deserialize(rdr);
and i get the next error message:
InnerException = {"LowFareSearchRsp xmlns='' was not expected."}
here is the object:
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace Xml2CSharp
{
[XmlRoot(ElementName = "FlightDetails")]
public class FlightDetails
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "Origin")]
public string Origin { get; set; }
[XmlAttribute(AttributeName = "Destination")]
public string Destination { get; set; }
[XmlAttribute(AttributeName = "DepartureTime")]
public string DepartureTime { get; set; }
[XmlAttribute(AttributeName = "ArrivalTime")]
public string ArrivalTime { get; set; }
[XmlAttribute(AttributeName = "FlightTime")]
public string FlightTime { get; set; }
[XmlAttribute(AttributeName = "TravelTime")]
public string TravelTime { get; set; }
[XmlAttribute(AttributeName = "Equipment")]
public string Equipment { get; set; }
[XmlAttribute(AttributeName = "DestinationTerminal")]
public string DestinationTerminal { get; set; }
}
[XmlRoot(ElementName = "FlightDetailsList")]
public class FlightDetailsList
{
[XmlElement(ElementName = "FlightDetails")]
public List<FlightDetails> FlightDetails { get; set; }
}
[XmlRoot(ElementName = "BookingCodeInfo")]
public class BookingCodeInfo
{
[XmlAttribute(AttributeName = "BookingCounts")]
public string BookingCounts { get; set; }
}
[XmlRoot(ElementName = "AirAvailInfo")]
public class AirAvailInfo
{
[XmlElement(ElementName = "BookingCodeInfo")]
public BookingCodeInfo BookingCodeInfo { get; set; }
[XmlAttribute(AttributeName = "ProviderCode")]
public string ProviderCode { get; set; }
}
[XmlRoot(ElementName = "FlightDetailsRef")]
public class FlightDetailsRef
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
}
[XmlRoot(ElementName = "AirSegment")]
public class AirSegment
{
[XmlElement(ElementName = "AirAvailInfo")]
public AirAvailInfo AirAvailInfo { get; set; }
[XmlElement(ElementName = "FlightDetailsRef")]
public FlightDetailsRef FlightDetailsRef { get; set; }
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "Group")]
public string Group { get; set; }
[XmlAttribute(AttributeName = "Carrier")]
public string Carrier { get; set; }
[XmlAttribute(AttributeName = "FlightNumber")]
public string FlightNumber { get; set; }
[XmlAttribute(AttributeName = "Origin")]
public string Origin { get; set; }
[XmlAttribute(AttributeName = "Destination")]
public string Destination { get; set; }
[XmlAttribute(AttributeName = "DepartureTime")]
public string DepartureTime { get; set; }
[XmlAttribute(AttributeName = "ArrivalTime")]
public string ArrivalTime { get; set; }
[XmlAttribute(AttributeName = "FlightTime")]
public string FlightTime { get; set; }
[XmlAttribute(AttributeName = "Distance")]
public string Distance { get; set; }
[XmlAttribute(AttributeName = "ETicketability")]
public string ETicketability { get; set; }
[XmlAttribute(AttributeName = "Equipment")]
public string Equipment { get; set; }
[XmlAttribute(AttributeName = "ChangeOfPlane")]
public string ChangeOfPlane { get; set; }
[XmlAttribute(AttributeName = "ParticipantLevel")]
public string ParticipantLevel { get; set; }
[XmlAttribute(AttributeName = "LinkAvailability")]
public string LinkAvailability { get; set; }
[XmlAttribute(AttributeName = "PolledAvailabilityOption")]
public string PolledAvailabilityOption { get; set; }
[XmlAttribute(AttributeName = "OptionalServicesIndicator")]
public string OptionalServicesIndicator { get; set; }
[XmlAttribute(AttributeName = "AvailabilitySource")]
public string AvailabilitySource { get; set; }
[XmlAttribute(AttributeName = "AvailabilityDisplayType")]
public string AvailabilityDisplayType { get; set; }
[XmlElement(ElementName = "CodeshareInfo")]
public CodeshareInfo CodeshareInfo { get; set; }
}
[XmlRoot(ElementName = "CodeshareInfo")]
public class CodeshareInfo
{
[XmlAttribute(AttributeName = "OperatingCarrier")]
public string OperatingCarrier { get; set; }
[XmlAttribute(AttributeName = "OperatingFlightNumber")]
public string OperatingFlightNumber { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "AirSegmentList")]
public class AirSegmentList
{
[XmlElement(ElementName = "AirSegment")]
public List<AirSegment> AirSegment { get; set; }
}
[XmlRoot(ElementName = "BaggageAllowance")]
public class BaggageAllowance
{
[XmlElement(ElementName = "NumberOfPieces")]
public string NumberOfPieces { get; set; }
[XmlElement(ElementName = "MaxWeight")]
public string MaxWeight { get; set; }
}
[XmlRoot(ElementName = "FareRuleKey")]
public class FareRuleKey
{
[XmlAttribute(AttributeName = "FareInfoRef")]
public string FareInfoRef { get; set; }
[XmlAttribute(AttributeName = "ProviderCode")]
public string ProviderCode { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "FareInfo")]
public class FareInfo
{
[XmlElement(ElementName = "BaggageAllowance")]
public BaggageAllowance BaggageAllowance { get; set; }
[XmlElement(ElementName = "FareRuleKey")]
public FareRuleKey FareRuleKey { get; set; }
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "FareBasis")]
public string FareBasis { get; set; }
[XmlAttribute(AttributeName = "PassengerTypeCode")]
public string PassengerTypeCode { get; set; }
[XmlAttribute(AttributeName = "Origin")]
public string Origin { get; set; }
[XmlAttribute(AttributeName = "Destination")]
public string Destination { get; set; }
[XmlAttribute(AttributeName = "EffectiveDate")]
public string EffectiveDate { get; set; }
[XmlAttribute(AttributeName = "DepartureDate")]
public string DepartureDate { get; set; }
[XmlAttribute(AttributeName = "Amount")]
public string Amount { get; set; }
[XmlAttribute(AttributeName = "NegotiatedFare")]
public string NegotiatedFare { get; set; }
[XmlAttribute(AttributeName = "PrivateFare")]
public string PrivateFare { get; set; }
[XmlAttribute(AttributeName = "NotValidBefore")]
public string NotValidBefore { get; set; }
[XmlAttribute(AttributeName = "NotValidAfter")]
public string NotValidAfter { get; set; }
[XmlAttribute(AttributeName = "PseudoCityCode")]
public string PseudoCityCode { get; set; }
}
[XmlRoot(ElementName = "FareInfoList")]
public class FareInfoList
{
[XmlElement(ElementName = "FareInfo")]
public List<FareInfo> FareInfo { get; set; }
}
[XmlRoot(ElementName = "Leg")]
public class Leg
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "Group")]
public string Group { get; set; }
[XmlAttribute(AttributeName = "Origin")]
public string Origin { get; set; }
[XmlAttribute(AttributeName = "Destination")]
public string Destination { get; set; }
}
[XmlRoot(ElementName = "Route")]
public class Route
{
[XmlElement(ElementName = "Leg")]
public Leg Leg { get; set; }
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
}
[XmlRoot(ElementName = "RouteList")]
public class RouteList
{
[XmlElement(ElementName = "Route")]
public Route Route { get; set; }
}
[XmlRoot(ElementName = "AirSegmentRef")]
public class AirSegmentRef
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
}
[XmlRoot(ElementName = "Journey")]
public class Journey
{
[XmlElement(ElementName = "AirSegmentRef")]
public AirSegmentRef AirSegmentRef { get; set; }
[XmlAttribute(AttributeName = "TravelTime")]
public string TravelTime { get; set; }
}
[XmlRoot(ElementName = "LegRef")]
public class LegRef
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
}
[XmlRoot(ElementName = "FareInfoRef")]
public class FareInfoRef
{
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
}
[XmlRoot(ElementName = "BookingInfo")]
public class BookingInfo
{
[XmlAttribute(AttributeName = "BookingCode")]
public string BookingCode { get; set; }
[XmlAttribute(AttributeName = "CabinClass")]
public string CabinClass { get; set; }
[XmlAttribute(AttributeName = "FareInfoRef")]
public string FareInfoRef { get; set; }
[XmlAttribute(AttributeName = "SegmentRef")]
public string SegmentRef { get; set; }
}
[XmlRoot(ElementName = "TaxInfo")]
public class TaxInfo
{
[XmlAttribute(AttributeName = "Category")]
public string Category { get; set; }
[XmlAttribute(AttributeName = "Amount")]
public string Amount { get; set; }
}
[XmlRoot(ElementName = "PassengerType")]
public class PassengerType
{
[XmlAttribute(AttributeName = "Code")]
public string Code { get; set; }
[XmlAttribute(AttributeName = "Age")]
public string Age { get; set; }
}
[XmlRoot(ElementName = "ChangePenalty")]
public class ChangePenalty
{
[XmlElement(ElementName = "Amount")]
public string Amount { get; set; }
}
[XmlRoot(ElementName = "AirPricingInfo")]
public class AirPricingInfo
{
[XmlElement(ElementName = "FareInfoRef")]
public FareInfoRef FareInfoRef { get; set; }
[XmlElement(ElementName = "BookingInfo")]
public BookingInfo BookingInfo { get; set; }
[XmlElement(ElementName = "TaxInfo")]
public List<TaxInfo> TaxInfo { get; set; }
[XmlElement(ElementName = "FareCalc")]
public string FareCalc { get; set; }
[XmlElement(ElementName = "PassengerType")]
public PassengerType PassengerType { get; set; }
[XmlElement(ElementName = "ChangePenalty")]
public ChangePenalty ChangePenalty { get; set; }
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "TotalPrice")]
public string TotalPrice { get; set; }
[XmlAttribute(AttributeName = "BasePrice")]
public string BasePrice { get; set; }
[XmlAttribute(AttributeName = "ApproximateTotalPrice")]
public string ApproximateTotalPrice { get; set; }
[XmlAttribute(AttributeName = "ApproximateBasePrice")]
public string ApproximateBasePrice { get; set; }
[XmlAttribute(AttributeName = "Taxes")]
public string Taxes { get; set; }
[XmlAttribute(AttributeName = "ApproximateTaxes")]
public string ApproximateTaxes { get; set; }
[XmlAttribute(AttributeName = "LatestTicketingTime")]
public string LatestTicketingTime { get; set; }
[XmlAttribute(AttributeName = "PricingMethod")]
public string PricingMethod { get; set; }
[XmlAttribute(AttributeName = "ETicketability")]
public string ETicketability { get; set; }
[XmlAttribute(AttributeName = "PlatingCarrier")]
public string PlatingCarrier { get; set; }
[XmlAttribute(AttributeName = "ProviderCode")]
public string ProviderCode { get; set; }
}
[XmlRoot(ElementName = "AirPricingSolution")]
public class AirPricingSolution
{
[XmlElement(ElementName = "Journey")]
public Journey Journey { get; set; }
[XmlElement(ElementName = "LegRef")]
public LegRef LegRef { get; set; }
[XmlElement(ElementName = "AirPricingInfo")]
public AirPricingInfo AirPricingInfo { get; set; }
[XmlAttribute(AttributeName = "Key")]
public string Key { get; set; }
[XmlAttribute(AttributeName = "TotalPrice")]
public string TotalPrice { get; set; }
[XmlAttribute(AttributeName = "BasePrice")]
public string BasePrice { get; set; }
[XmlAttribute(AttributeName = "ApproximateTotalPrice")]
public string ApproximateTotalPrice { get; set; }
[XmlAttribute(AttributeName = "ApproximateBasePrice")]
public string ApproximateBasePrice { get; set; }
[XmlAttribute(AttributeName = "Taxes")]
public string Taxes { get; set; }
[XmlAttribute(AttributeName = "ApproximateTaxes")]
public string ApproximateTaxes { get; set; }
}
[XmlRoot(ElementName = "LowFareSearchRsp")]
public class LowFareSearchRsp
{
[XmlElement(ElementName = "FlightDetailsList")]
public FlightDetailsList FlightDetailsList { get; set; }
[XmlElement(ElementName = "AirSegmentList")]
public AirSegmentList AirSegmentList { get; set; }
[XmlElement(ElementName = "FareInfoList")]
public FareInfoList FareInfoList { get; set; }
[XmlElement(ElementName = "RouteList")]
public RouteList RouteList { get; set; }
[XmlElement(ElementName = "AirPricingSolution")]
public List<AirPricingSolution> AirPricingSolution { get; set; }
[XmlAttribute(AttributeName = "TransactionId")]
public string TransactionId { get; set; }
[XmlAttribute(AttributeName = "ResponseTime")]
public string ResponseTime { get; set; }
[XmlAttribute(AttributeName = "DistanceUnits")]
public string DistanceUnits { get; set; }
[XmlAttribute(AttributeName = "CurrencyType")]
public string CurrencyType { get; set; }
[XmlAttribute(AttributeName = "air", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Air { get; set; }
}
}
here is the XML:
<LowFareSearchRsp TransactionId="2D7A0AD80A07643BB75C03CA78C9877F" ResponseTime="2378" DistanceUnits="MI" CurrencyType="EUR" xmlns:air="http://www.travelport.com/schema/air_v28_0"><FlightDetailsList><FlightDetails Key="Q0tqCkHxQfqBJpSbN+LtXQ==" Origin="AMS" Destination="LHR" DepartureTime="2016-03-01T08:35:00.000+01:00" ArrivalTime="2016-03-01T09:00:00.000+00:00" FlightTime="85" TravelTime="85" Equipment="737" DestinationTerminal="4" /><FlightDetails Key="w1vkvs2sQayOxIHugEe06Q==" Origin="AMS" Destination="LCY" DepartureTime="2016-03-01T08:45:00.000+01:00" ArrivalTime="2016-03-01T09:00:00.000+00:00" FlightTime="75" TravelTime="75" Equipment="AR8" /><FlightDetails Key="F5zR9xf/TEe8sjwHe0Lgfg==" Origin="AMS" Destination="LCY" DepartureTime="2016-03-01T08:00:00.000+01:00" ArrivalTime="2016-03-01T08:10:00.000+00:00" FlightTime="70" TravelTime="70" Equipment="AR8" /></FlightDetailsList><AirSegmentList><AirSegment Key="0uT0Eex8R+q0AGhindSZJw==" Group="0" Carrier="KL" FlightNumber="1007" Origin="AMS" Destination="LHR" DepartureTime="2016-03-01T08:35:00.000+01:00" ArrivalTime="2016-03-01T09:00:00.000+00:00" FlightTime="85" Distance="211" ETicketability="Yes" Equipment="737" ChangeOfPlane="false" ParticipantLevel="Secure Sell" LinkAvailability="true" PolledAvailabilityOption="Polled avail used" OptionalServicesIndicator="false" AvailabilitySource="S" AvailabilityDisplayType="Fare Shop/Optimal Shop"><AirAvailInfo ProviderCode="1G"><BookingCodeInfo BookingCounts="J5|C4|D3|I3|Z2|Y9|B9|M9|U9|K9|W9|H0|S9|L0|A0|Q0|T0|E0|N0|R0|V0|X0|G0" /></AirAvailInfo><FlightDetailsRef Key="Q0tqCkHxQfqBJpSbN+LtXQ==" /></AirSegment><AirSegment Key="Xou2ll85S+qgxInLw5cppA==" Group="0" Carrier="KL" FlightNumber="2404" Origin="AMS" Destination="LCY" DepartureTime="2016-03-01T08:45:00.000+01:00" ArrivalTime="2016-03-01T09:00:00.000+00:00" FlightTime="75" Distance="211" ETicketability="Yes" Equipment="AR8" ChangeOfPlane="false" ParticipantLevel="Secure Sell" LinkAvailability="true" PolledAvailabilityOption="Polled avail used" OptionalServicesIndicator="false" AvailabilitySource="S" AvailabilityDisplayType="Fare Shop/Optimal Shop"><CodeshareInfo OperatingCarrier="WX" OperatingFlightNumber="184">CITY JET</CodeshareInfo><AirAvailInfo ProviderCode="1G"><BookingCodeInfo BookingCounts="J9|C9|D9|I9|Z9|Y9|B9|M9|U9|K9|W9|H9|S9|L6|A9|Q9|T6|E0|N0|R0|V0|G0" /></AirAvailInfo><FlightDetailsRef Key="w1vkvs2sQayOxIHugEe06Q==" /></AirSegment><AirSegment Key="1w6HTv96SXWWuLY0Pe2QuQ==" Group="0" Carrier="KL" FlightNumber="2402" Origin="AMS" Destination="LCY" DepartureTime="2016-03-01T08:00:00.000+01:00" ArrivalTime="2016-03-01T08:10:00.000+00:00" FlightTime="70" Distance="211" ETicketability="Yes" Equipment="AR8" ChangeOfPlane="false" ParticipantLevel="Secure Sell" LinkAvailability="true" PolledAvailabilityOption="Polled avail used" OptionalServicesIndicator="false" AvailabilitySource="S" AvailabilityDisplayType="Fare Shop/Optimal Shop"><CodeshareInfo OperatingCarrier="WX" OperatingFlightNumber="182">CITY JET</CodeshareInfo><AirAvailInfo ProviderCode="1G"><BookingCodeInfo BookingCounts="J9|C9|D9|I9|Z9|Y9|B9|M9|U9|K9|W9|H9|S9|L6|A9|Q9|T6|E0|N0|R0|V0|G0" /></AirAvailInfo><FlightDetailsRef Key="F5zR9xf/TEe8sjwHe0Lgfg==" /></AirSegment></AirSegmentList><FareInfoList><FareInfo Key="/2JzpaPgR4GHLl4HEnIiZg==" FareBasis="KBAGYNL" PassengerTypeCode="ADT" Origin="AMS" Destination="LHR" EffectiveDate="2016-02-29T15:41:00.000+01:00" DepartureDate="2016-03-01" Amount="EUR133.00" NegotiatedFare="false" PrivateFare="AirlinePrivateFare" NotValidBefore="2016-03-01" NotValidAfter="2016-03-01" PseudoCityCode="7LD2"><BaggageAllowance><NumberOfPieces>1</NumberOfPieces><MaxWeight /></BaggageAllowance><FareRuleKey FareInfoRef="/2JzpaPgR4GHLl4HEnIiZg==" ProviderCode="1G">6UUVoSldxwglWqQxEnyq/cbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe9/ilBar8RBLwtrZnoOgR1cYHR4az4coGwd2gmBPo1O6ASmIQpER2x0wNY5k1+MQrLCjWzPlFL6jYBR1VjXHCoG1PqzaFGsJo/E8Wy+Z6VUptu1Q7ZKxyGrtZySrXDhOpdi8VZ+tr8Yjcw61JCjZInRzWhUTy56VK0Y+V0ELMq+/Sutrg11uaZNEQ+ZLml8hMrbyQOwi+ESbfUKpUJwmWYGbGOyXec3aXsoJsodpwGFHJHXyDAS6XXKrSeiEQqx4y86wIJ070sjSq2Mkfg7v2+hW8vSBNa8ZUuJYtF79PC3YsxYLUKGiXKW7eP3a4bhHZA0g8fgZiGj0Vesixah9noHg2BMJ0qOmdc4YTCgtCVCcN49GIwD0nwinN0QJSoeu5/wBShF29N4Sv4Xvb2u1Qx+/he9va7VDH7+F729rtUMfv4Xvb2u1Qx8Qxibp/OJehpo2LrM59tO1jp8ZENljzx72lVAJ3nO/P4n+Mxf03TJScktxA0VgKcbS+gYtjsYoLmbFZUBdXZs1</FareRuleKey></FareInfo><FareInfo Key="vOp7x5iCTnaOfEJmIceWdQ==" FareBasis="HBAGYNL" PassengerTypeCode="ADT" Origin="AMS" Destination="LCY" EffectiveDate="2016-02-29T15:41:00.000+01:00" DepartureDate="2016-03-01" Amount="EUR294.00" NegotiatedFare="false" PrivateFare="AirlinePrivateFare" NotValidBefore="2016-03-01" NotValidAfter="2016-03-01" PseudoCityCode="7LD2"><BaggageAllowance><NumberOfPieces>1</NumberOfPieces><MaxWeight /></BaggageAllowance><FareRuleKey FareInfoRef="vOp7x5iCTnaOfEJmIceWdQ==" ProviderCode="1G">6UUVoSldxwglWqQxEnyq/cbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe/r7UOc8hVd+I/+NqP0rKzLusgtyd1y6qgP9G0W6IHlhpqZ6lb6AP0xNjTzzGmA6/Urra4NdbmmTzFOd+W7w/UzJ2lQug+wKWM3BdGL2xyFSNsm3fw/kMAOxMmAX3SbpGDy3fBfc+mJVEPaEs+237t0eSBuiOpSk/gzsLeFdZfeBzi5JKGVGwBPPOvXkrT+ckAxdqLsZnUAM83fZ3yCAPapY9YklFLj9Z/MCXrZl6G/oVCulqMwbpNbfH3zc0NhSMKqdj8Ih8qyqVnAnvWMa00Sdw/Am9T/DRMsiOHFaFMf8GWXoXHIgLpyVqfCTByZWB+lREtwo3mkOzK0Iy0HMiGbqNbjwzJx7oqPv19h9EZpQEQ4DmK2C6uFH/+bkQTnfvoq+cJFUBzrily5qxZ3qLwOXLmrFneovA5cuasWd6i8Dly5qxZ3qLwOXLmrFneovA3N5jV9Rrzq8txHW6jzw2UbAQJCzzE4cyQuLI8q+Wie1FwDp7I8hPtiGaLihfOSYJ8Bo4QYxmFzt</FareRuleKey></FareInfo></FareInfoList><RouteList><Route Key="rX1yXg7iR4+opM4/Ol7rrw=="><Leg Key="NYqOScjGQESvuXuIGUjFqg==" Group="0" Origin="AMS" Destination="LON" /></Route></RouteList><AirPricingSolution Key="uIwAvUxtTuK4hqFLGAnJaQ==" TotalPrice="EUR160.05" BasePrice="EUR133.00" ApproximateTotalPrice="EUR160.05" ApproximateBasePrice="EUR133.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05"><Journey TravelTime="P0DT1H25M0S"><AirSegmentRef Key="0uT0Eex8R+q0AGhindSZJw==" /></Journey><LegRef Key="NYqOScjGQESvuXuIGUjFqg==" /><AirPricingInfo Key="8DDuD5q9TTWmR6+Y1QIPuQ==" TotalPrice="EUR160.05" BasePrice="EUR133.00" ApproximateTotalPrice="EUR160.05" ApproximateBasePrice="EUR133.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05" LatestTicketingTime="2016-03-01T23:59:00.000+01:00" PricingMethod="GuaranteedUsingAirlinePrivateFare" ETicketability="Yes" PlatingCarrier="KL" ProviderCode="1G"><FareInfoRef Key="/2JzpaPgR4GHLl4HEnIiZg==" /><BookingInfo BookingCode="K" CabinClass="Economy" FareInfoRef="/2JzpaPgR4GHLl4HEnIiZg==" SegmentRef="0uT0Eex8R+q0AGhindSZJw==" /><TaxInfo Category="CJ" Amount="EUR12.17" /><TaxInfo Category="RN" Amount="EUR14.38" /><TaxInfo Category="VV" Amount="EUR0.50" /><FareCalc>AMS KL LON 144.81KBAGYNL NUC144.81END ROE0.918404</FareCalc><PassengerType Code="ADT" Age="20" /><ChangePenalty><Amount>EUR70.00</Amount></ChangePenalty></AirPricingInfo></AirPricingSolution><AirPricingSolution Key="4Og1WgNSQf6r7WHXpetyqA==" TotalPrice="EUR321.05" BasePrice="EUR294.00" ApproximateTotalPrice="EUR321.05" ApproximateBasePrice="EUR294.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05"><Journey TravelTime="P0DT1H15M0S"><AirSegmentRef Key="Xou2ll85S+qgxInLw5cppA==" /></Journey><LegRef Key="NYqOScjGQESvuXuIGUjFqg==" /><AirPricingInfo Key="hauIf2TLRE+xSFkaJa1bAQ==" TotalPrice="EUR321.05" BasePrice="EUR294.00" ApproximateTotalPrice="EUR321.05" ApproximateBasePrice="EUR294.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05" LatestTicketingTime="2016-03-01T23:59:00.000+01:00" PricingMethod="GuaranteedUsingAirlinePrivateFare" ETicketability="Yes" PlatingCarrier="KL" ProviderCode="1G"><FareInfoRef Key="vOp7x5iCTnaOfEJmIceWdQ==" /><BookingInfo BookingCode="H" CabinClass="Economy" FareInfoRef="vOp7x5iCTnaOfEJmIceWdQ==" SegmentRef="Xou2ll85S+qgxInLw5cppA==" /><TaxInfo Category="CJ" Amount="EUR12.17" /><TaxInfo Category="RN" Amount="EUR14.38" /><TaxInfo Category="VV" Amount="EUR0.50" /><FareCalc>AMS KL LON 320.12HBAGYNL NUC320.12END ROE0.918404</FareCalc><PassengerType Code="ADT" Age="20" /><ChangePenalty><Amount>EUR70.00</Amount></ChangePenalty></AirPricingInfo></AirPricingSolution><AirPricingSolution Key="VD1GnxpWQJi/4emcBGZTKQ==" TotalPrice="EUR321.05" BasePrice="EUR294.00" ApproximateTotalPrice="EUR321.05" ApproximateBasePrice="EUR294.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05"><Journey TravelTime="P0DT1H10M0S"><AirSegmentRef Key="1w6HTv96SXWWuLY0Pe2QuQ==" /></Journey><LegRef Key="NYqOScjGQESvuXuIGUjFqg==" /><AirPricingInfo Key="OvfECYiLRraifkOqyl1qGA==" TotalPrice="EUR321.05" BasePrice="EUR294.00" ApproximateTotalPrice="EUR321.05" ApproximateBasePrice="EUR294.00" Taxes="EUR27.05" ApproximateTaxes="EUR27.05" LatestTicketingTime="2016-03-01T23:59:00.000+01:00" PricingMethod="GuaranteedUsingAirlinePrivateFare" ETicketability="Yes" PlatingCarrier="KL" ProviderCode="1G"><FareInfoRef Key="vOp7x5iCTnaOfEJmIceWdQ==" /><BookingInfo BookingCode="H" CabinClass="Economy" FareInfoRef="vOp7x5iCTnaOfEJmIceWdQ==" SegmentRef="1w6HTv96SXWWuLY0Pe2QuQ==" /><TaxInfo Category="CJ" Amount="EUR12.17" /><TaxInfo Category="RN" Amount="EUR14.38" /><TaxInfo Category="VV" Amount="EUR0.50" /><FareCalc>AMS KL LON 320.12HBAGYNL NUC320.12END ROE0.918404</FareCalc><PassengerType Code="ADT" Age="20" /><ChangePenalty><Amount>EUR70.00</Amount></ChangePenalty></AirPricingInfo></AirPricingSolution></LowFareSearchRsp>
im stuck on it.
please help.
after small edits in your code it works fine for me:
XmlSerializer serialize = new XmlSerializer(typeof(UnitTestProject.LowFareSearchRsp));
StringReader rdr = new StringReader(xml);
LowFareSearchRsp res = (LowFareSearchRsp)serialize.Deserialize(rdr);
Shortly, you have wrong type of res: LowFareSearchCorpRsp instead of LowFareSearchRsp