![](/img/trans.png)
[英]Getting Child nodes of an xDocument element while itereating through the Xdocument
[英]Count child nodes on XDocument
有沒有辦法計算XDocument上的子節點?
我找了一個計數方法或屬性,找不到一個。
謝謝獅子座
var doc = XDocument.Load(fileName);
int descendantsCount = doc.Descendants().Count(); // counts ALL descendants elements
int childrenCount = doc.Root.Elements().Count(); // counts direct children of the root element
或者......如果您知道元素的名稱永遠不會改變並且它們始終存在,
XDocument xD = XDocument.Load(XmlFullFileName);
XElement xE_ParameterSets = xD.Root.Element("Report").Element("ParameterSets");
int index = ((IEnumerable<XElement>)xE_ParameterSets.Elements()).Count();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.