<CompanyRoot>
<Company>
<Name>Courier</Name>
<Company>
<Name>Dhl</Name>
<Company>
<Name>Test1</Name>
</Company>
<Company>
<Name>Test4</Name>
<Company>
<Name>Test5</Name>
</Company>
</Company>
</Company>
<Company>
<Name>BlueDart</Name>
<Company>
<Name>Test3</Name>
</Company>
</Company>
<Company>
<Name>FastFlight</Name>
</Company>
</Company>
</CompanyRoot>
I have an xml where I want the count of xml descendants at same level ie The count of descendants of "Courier" should be 3(DHL/Bluedart/Fastflight) instead of seven is there a way possible in c#
Descendants
找到所有后代-您只需要直接的子元素:
var count = xElem.Elements("Company").Count();
评估这个Xpath表达式 :
count(/*/Company)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.