我嘗試計數,然後顯示xml文件中有多少個innerText
是相同的。我發現這個代碼來計算存在多少個相等的節點,但沒有多少等於innerText
。如何統計xml文件中相同innerText的數量?
var doc = new XmlDocument();
doc.Load(path_to_xml);
var result = from XmlNode n in doc.SelectNodes("//task/*")
group n by n.InnerText into g
select new {
Text = g.Key,
Count = g.Count()
};
例如,我有一個這樣的XML:
<rootNode>
<foo>
<first>stackoverflow</first>
<second>stackoverflow</second>
<third>superuser</third>
</foo>
</rootNode>
現在,我應該得到這一結果:
stackoverflow: Count 2
superuser: Count 1
有沒有辦法做到這一點?我使用XmlDocument
解析XML。
有什麼建議嗎? :)
看起來這是對的innerText>'n組由n.InnerText到g'? – Yahya
那就是我首先想到的,但它只是計數我的節點 – Tyler
你想要什麼呢? – Yahya