gpt4 book ai didi

c# - 使用 C# 读取 Soap 消息

转载 作者:可可西里 更新时间:2023-11-01 08:37:48 25 4
gpt4 key购买 nike

<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# 读取上面的 soap 消息 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;
}

计数始终为零,并且它不会读取预订状态值。

最佳答案

BookHotelResponse 位于命名空间 urn:schemas-test:testgate:hotel:2012-06(示例 xml 中的默认命名空间)中,因此您需要提供查询中的命名空间:

XmlDocument document = new XmlDocument(); 
document.LoadXml(soapmessage); //loading soap message as string
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);

manager.AddNamespace("d", "http://someURL");
manager.AddNamespace("bhr", "urn:schemas-test:testgate:hotel:2012-06");

XmlNodeList xnList = document.SelectNodes("//bhr:bookHotelResponse", manager);
int nodes = xnList.Count;

foreach (XmlNode xn in xnList)
{
Status = xn["d:bookingStatus"].InnerText;
}

关于c# - 使用 C# 读取 Soap 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12201822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com