我有一个获得这个格式的XML响应如何读取一个XML节点以这种格式
<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n
<PlatformResponse xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://platform.intuit.com/api/v1\">\r\n
<ErrorMessage>OAuth Token rejected</ErrorMessage>\r\n
<ErrorCode>270</ErrorCode>\r\n
<ServerTime>2012-06-19T00:01:31.5150146Z</ServerTime>\r\n
</PlatformResponse>
我需要抢在<ErrorCode>
节点的值,我做了以下内容,但它没有得到任何价值..
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlResponse);
XmlNodeList xnList = xml.SelectNodes("PlatformResponse");
foreach (XmlNode xn in xnList)
{
result.Message = xn["ErrorCode"].InnerText;
}
任何帮助将不胜感激。
如果只有一个错误代码,直接抓取值,使用:'XmlNode errNode = doc.SelectSingleNode(“/ PlatformResponse/ErrorCode”);'然后参考'errNode.InnerText' – mj82