我有下面的 xml,我试图从中获取HotelCrossRefElementResponseHotelCode属性的值。我已经尝试过下面的代码,但我得到了 0 Count in XmlNodeListstring xmlResp = @"<?xml version=""1.0"" encoding=""utf-8""?><OTA_HotelDescriptiveContentNotifRS xmlns=""http://www.opentravel.org/OTA/2003/05"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.opentravel.org/OTA/2003/05 OTA_HotelDescriptiveContentNotifRS.xsd"" TimeStamp=""2015-07-31T12:36:23-00:00"" Target=""Test"" Version=""3.000""><UniqueID Type=""10"" ID=""1460495"" /><TPA_Extensions><HotelCrossRefs><HotelCrossRef RequestHotelCode=""101010"" ResponseHotelCode=""1460495"" /></HotelCrossRefs></TPA_Extensions><Success /></OTA_HotelDescriptiveContentNotifRS>";XmlDocument xmlDocument = new XmlDocument();xmlDocument.LoadXml(xmlResp);XmlNodeList xnList = xmlDocument.SelectNodes("/OTA_HotelDescriptiveContentNotifRS/TPA_Extensions/HotelCrossRefs");foreach (XmlNode xn in xnList){ if (xn.HasChildNodes) { foreach (XmlNode childNode in xn.ChildNodes) { string id = childNode.Attributes["ResponseHotelCode"].Value; Console.WriteLine(id); } }}
1 回答
- 1 回答
- 0 关注
- 270 浏览
添加回答
举报
0/150
提交
取消