【发布时间】:2012-08-30 16:53:37
【问题描述】:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Head>
<h:talkId s:mustknow="1" xmlns:h="urn:schemas-test:testgate:hotel:2012-06">
sfasfasfasfsfsf</h:talkId>
</s:Head>
<s:Body>
<bookHotelResponse xmlns="urn:schemas-test:testgate:hotel:2012-06" xmlns:d="http://someURL" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d:bookingReference>123456</d:bookingReference>
<d:bookingStatus>successful</d:bookingStatus>
<d:price xmlns:p="moreURL">
<d:total>105</d:total>
</d:price>
</bookHotelResponse>
</s:Body>
</s:Envelope>
我正在尝试使用 C# 阅读上述肥皂消息 XmlDocument:
XmlDocument document = new XmlDocument();
document.LoadXml(soapmessage); //loading soap message as string
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("d", "http://someURL");
XmlNodeList xnList = document.SelectNodes("//bookHotelResponse", manager);
int nodes = xnList.Count;
foreach (XmlNode xn in xnList)
{
Status = xn["d:bookingStatus"].InnerText;
}
计数始终为零,并且不读取 bookingstatus 值。
【问题讨论】:
-
请修正格式,尤其是 XML 消息的格式(目前大部分都丢失了)。
-
xml 无效...b 是未定义的命名空间...是 d
-
@anirudha 含义,xml 样本中的 b:total 应该是 d:total
-
并且 与
不匹配。在“id”的数量上因一个错误而关闭。