如下:记得把XML放Debug目录下,这样才能找到此XML文件
string path = "XML文件名";
XmlDocument xmldoc = new XmlDocument(); //实例化XML操作对象
xmldoc.Load(path); //加载XML操作文档
int count= xmldoc.SelectNodes("/viewer/item[@id='1']").Count; //过滤节点属于得到Count总个数
count就是你要id=1 item节点有多少个
希望能帮到你!
var path = System.Web.HttpContext.Current.Server.MapPath("\\App_Data\\SiteConfig.xml");
var xDoc = XDocument.Load(path);
var p = from x in xDoc.Descendants("xxx")
where x.Attribute("item").Value == "1"
select x;
p.Count();
string path = HttpContext.Current.Server.MapPath("文档路径");
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(path);
XmlNodeList root = xmldoc.SelectSingleNode("//viewer/item[@id='1']");