2015-03-18 4 views
0

Привет Пожалуйста, проверьте ниже моего Soap XML ResponseЧтение SOAP XML-ответ в C#

<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> 
<soapenv:Body> 
<ns1:getHotelDetail xsi:type='xsd:string' xmlns:ns1='http://axis.frontend.hydra.hotelbeds.com'> 
<HotelDetailRS xmlns='http://www.hotelbeds.com/schemas/2005/06/messages' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.hotelbeds.com/schemas/2005/06/messages HotelDetailRS.xsd' echoToken='DummyEchoToken'> 
<AuditData> 
<ProcessTime>15</ProcessTime><Timestamp>2015-03-18 11:30:23.486</Timestamp><RequestHost>54.169.51.224</RequestHost> <ServerName>FORM</ServerName><ServerId>FO</ServerId><SchemaRelease>2005/06</SchemaRelease><HydraCoreRelease>2015.01.14</HydraCoreRelease><HydraEnumerationsRelease>N/A</HydraEnumerationsRelease><MerlinRelease>0</MerlinRelease></AuditData><Hotel xsi:type='ProductHotel'><Code>52319</Code><Name>Intertur Apartamentos Waikiki</Name> 

Выше мой XML Ответ на части. Но я не могу прочитать этот файл в C# Пожалуйста, проверьте мою C# Перетяжку ниже

private void GetCustomerList(XmlDocument xml) 
{ 
    //string xmlFilePath = System.Configuration.ConfigurationManager.AppSettings.Get("xmlpathHotel"); 
    //int i = iRefreshID; 
    int icount = 0; 
    XmlDocument xdcDocument = new XmlDocument(); 

    xdcDocument = xml; 

    var nsmgr = new XmlNamespaceManager(xdcDocument.NameTable); 
    nsmgr.AddNamespace("ns1", "http://axis.frontend.hydra.hotelbeds.com"); 
    nsmgr.AddNamespace("ns", "http://www.hotelbeds.com/schemas/2005/06/messages"); 


    var nl = xdcDocument.SelectNodes("/ns:HotelDetailRS/ns:Hotel", nsmgr); 

    foreach (XmlNode xndNode in nl) 
    { 
     Label lbln = new Label(); 
     lbln.Text = "Code : " + xndNode["Code"].InnerText + "<br />"; ; 
     hdetDiv.Controls.Add(lbln); 

     Label lblnn = new Label(); 
     lblnn.Text = "Name : " + xndNode["Name"].InnerText + "<br />"; ; 
     hdetDiv.Controls.Add(lblnn); 

     Label lblad7 = new Label(); 
     lblad7.Text = "Category : " + xndNode["Category"].InnerText + "<br />"; ; 
     hdetDiv.Controls.Add(lblad7); 
    } 
} 

Xml пространств имен Я настраиваю сюда чтения XML-файл является неправильным. Кто-нибудь может мне помочь.

ответ

0

Вы можете попробовать использовать объект XDocument (LINQ to XML). Легче программировать против такого объекта, чем против XmlDocument.

XDocument xdoc = XDocument.Parse(xdcDocument.OuterXml); 
XNamespace ns = "http://www.hotelbeds.com/schemas/2005/06/messages"; 

foreach (XElement hotel in xdoc.Descendants(ns + "Hotel")) 
{ 
    string code = hotel.Element(ns + "Code").Value; 
    string name = hotel.Element(ns + "Name").Value; 
}