我从网络服务的SOAP信封的回应如下:提取XML在C#
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ProcessTranResponse xmlns="http://www.polaris.co.uk/XRTEService/2009/03/">
<ProcessTranResult xmlns:a="http://schemas.datacontract.org/2004/07/XRTEService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:PrintFormFileNameContents i:nil="true"/>
<a:ResponseXML>response_message</a:ResponseXML>
</ProcessTranResult>
</ProcessTranResponse>
</s:Body>
我想response_message
给一个字符串变量。我试着做
XDocument doc = XDocument.Parse(Response);
XNamespace xmlnsa = "http://schemas.datacontract.org/2004/07/XRTEService";
var ResponseXML = doc.Descendants(xmlnsa + "ResponseXML");
当我使用的手表我看到我的ResponseXML -> Results View[0] -> Value
response_message
,但我无法弄清楚什么是下一个步骤,从C#得到价值。
另外doc.Descendants(xmlnsa +“ResponseXML”)。First()。Value ;使用Linq工作。谢谢! – user1734523
不客气!请注意,如果后代列表为空,则'.First()'可能会抛出异常...... –
如果FirstOrDefault返回null,则''ResponseXML.Value'将引发异常。 –