【发布时间】:2019-06-28 12:09:29
【问题描述】:
对于下面的字符串xml值,我需要获取节点“ReturnStr”的值
<ArrayOfAppExportReturnStruct
xmlns=\"http://schemas.datacontract.org/2004/07/ClientWebService\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n
<AppExportReturnStruct>\r\n
<Key1>0</Key1>\r\n <Key2>0</Key2>\r\n
<PeriodDT>2019-02-26T00:00:00</PeriodDT>\r\n
<ReturnCode>1</ReturnCode>\r\n
<ReturnStr>Failure - No Deal found based on input parameters passed.</ReturnStr>\r\n
</AppExportReturnStruct>\r\n
</ArrayOfAppExportReturnStruct>
我使用了以下代码
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString.Replace("\r\n",""));
string alarmDesc;
string xpath = "ArrayOfAppExportReturnStruct/AppExportReturnStruct";
var nodes = xmlDoc.SelectNodes(xpath);
foreach (XmlNode childrenNode in nodes)
{
alarmDesc = childrenNode.SelectSingleNode("ReturnStr").InnerText;
}
我在节点 var 中一无所获。 在“alarmDesc”中获取 ReturnStr 节点值的正确方法是什么。
【问题讨论】: