Jam*_*mie 6 c# xml silverlight windows-phone-7
我想知道是否有可能计算XML文档中的元素数量,最好是能够使用类似的东西where (string)query.Attribute("attName") == att
.
根据我的知识,我尝试了以下但不幸的是,我似乎无法使它工作.
var listElements = reader.Elements("shortlist");
foreach (var element in listElements)
{
XElement _xml;
location.Position = 0;
System.IO.StreamReader file = new System.IO.StreamReader(location);
_xml = XElement.Parse(file.ReadToEnd());
XAttribute attName = _xml.Attribute("attN");
if (attName.Value == att)
{
Count++;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
Mat*_*len 10
鉴于doc是一个实例 XDocument
doc.Root.Descendants().Count(d => (string)d.Attribute("attName") == "value");
Run Code Online (Sandbox Code Playgroud)