例如xml串:<?xml version="1.0" encoding="UTF-16" standalone="yes"?> <root version="1.00.0965"><state success="true"></state><detailreprintflag>0</detailreprintflag></root> 想获取success值为true或者false 代码如下: string str = "<?xml version=\"1.0\" encoding=\"UTF - 16\" standalone=\"yes\"?><root version =\"1.00.0965\" ><state success =\"false\" ><error no =\"9014\" info =\"输入数据不能为空\" ></error ></state ></root >"; XmlDocument doc = new XmlDocument(); doc.LoadXml(str); XmlNode node = doc.SelectSingleNode("//root"); if (node != null) { int pos = 0; XmlNodeList itmes = node.ChildNodes; foreach (XmlNode xn in itmes) { string drawType = xn.Attributes["success"].Value;//获取success节点值
} }
标签:xml,node,success,C#,doc,itmes,节点 From: https://www.cnblogs.com/lydj/p/17145238.html