本人的C#语句报错,如下:
string sResult = “<?xml version=”1.0″ encoding=”utf-8″?><messStatus><status>1</status><error>0</error><seq>636071329920222657</seq></messStatus>”;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sResult);
foreach (XmlNode node in xmlDoc.SelectNodes(“messStatus”))
{
string code = node.FirstChild.Attributes[“status”].Value.ToString();
string zzz = node.FirstChild.Attributes[“error”].Value.ToString();
string sResult = “<?xml version=”1.0″ encoding=”utf-8″?><messStatus><status>1</status><error>0</error><seq>636071329920222657</seq></messStatus>”;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sResult);
foreach (XmlNode node in xmlDoc.SelectNodes(“messStatus”))
{
string code = node.FirstChild.Attributes[“status”].Value.ToString();
string zzz = node.FirstChild.Attributes[“error”].Value.ToString();
}
本人是实际需求是:
XML string语句如下,本人想读取出status和error的值,问一下怎么处理?
string sResult = “<?xml version=”1.0″ encoding=”utf-8″?><messStatus><status>1</status><error>0</error><seq>636071329920222657</seq></messStatus>”;
解决方案
20
InnerText
string sResult = "<?xml version="1.0" encoding="utf-8"?><messStatus><status>1</status><error>0</error><seq>636071329920222657</seq></messStatus>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(sResult); foreach (XmlNode node in doc.SelectNodes("messStatus")) { string code = node["status"].InnerText; string zzz = node["error"].InnerText; }