2016-06-12 1 views
0

J'essaie de désérialiser un fichier XML mais j'ai quelques problèmes.Problème de désialisation XML

Mon XML est,

<?xml version="1.0" encoding="UTF-8" ?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Body> 
     <WTR_BagsCreateRS xmlns:common="http://sita.aero/wtr/common/7/0" 
     xmlns:iata="http://www.iata.org/IATA/2007/00" xmlns="http://sita.aero/WTR_BagsCreateRS/7/0"> 
      <Success /> 
     <RecordID> 
      <common:RecordType>DELAYED</common:RecordType> 
      <common:RecordReference AirlineCode="QR" ReferenceNumber="10963" StationCode="DOH" /> 
     </RecordID> 
     </WTR_BagsCreateRS> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

C'est le type auquel je veux que le XML à désérialisée,

[Serializable] 
    [DesignerCategory("code")] 
    [DebuggerStepThrough] 
    [XmlType(AnonymousType = true, Namespace = "http://sita.aero/WTR_BagsCreateRS/7/0")] 
    [GeneratedCode("System.Xml", "4.0.30319.34283")] 
    [XmlRoot(IsNullable = false, Namespace = "http://www.sita.aero/WTR_BagsCreateRS/7/0")] 
    public class WTR_BagsCreateRS : INotifyPropertyChanged 
    { 
     public WTR_BagsCreateRS(); 

     [XmlElement("RecordID", typeof(RecordIdentifierType), Order = 0)] 
     [XmlElement("Errors", typeof(ErrorsType), Order = 0)] 
     [XmlElement("Warnings", typeof(WarningsType), Order = 0)] 
     [XmlElement("Success", typeof(SuccessType), Order = 0)] 
     public object[] Items { get; set; } 
     [XmlAttribute] 
     public WTR_LostPropertyRegisterRQModuleID ModuleID { get; set; } 

     public event PropertyChangedEventHandler PropertyChanged; 

     protected void RaisePropertyChanged(string propertyName); 
    } 

Et mon code desializing comme suit,

public static T DeserializeObject<T>(string xmlString) 
     { 
      T result; 

      XmlDocument doc = new XmlDocument(); 
      doc.LoadXml(xmlString); 
      XmlSerializer serializer = new XmlSerializer(typeof(T));//, new XmlRootAttribute("http://sita.aero/WTR_BagsCreateRS/7/0")); 
      var body = doc.GetElementsByTagName("SOAP-ENV:Body")[0]; 
      using (TextReader reader = new StringReader(body.InnerXml)) 
      { 
       result = (T)serializer.Deserialize(reader); 
      } 

      return result; 
     } 

Tout en désérialisant je fais face à la question ci-dessous, <WTR_BagsCreateRS xmlns='http://sita.aero/WTR_BagsCreateRS/7/0'> was not expected.

Répondre

1

Dans la définition de la classe qui vous est fourni

[XmlRoot(IsNullable = false, Namespace = "http://www.sita.aero/WTR_BagsCreateRS/7/0")] 

tout en XML que vous avez

xmlns="http://sita.aero/WTR_BagsCreateRS/7/0" 

Modifier l'espace de noms en supprimant www..