Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<Model name="Test.cre" version="v2.0" unit="m" count="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">



Here I want a particular component count and edit the Xml header count

How to do this at runtime using C#
Posted

Hi,

try this,
C#
var count = XDocument
    .Load("test.xml")
    .XPathSelectElements("//submenuid")
    .Count();
 
Share this answer
 
You know this, XmlNodeList.Count[^], right ??

XmlDocument.GetElementsByTagName[^] returns an XmlNodeList containing a list of all descendant elements that match the specified name.

See the examples on given links. :)

-KR
 
Share this answer
 
Comments
KUMAR619 17-Mar-14 2:33am    
Counting is not the problem sir.

My problem is that hoe to update count value in the header tag provided in the question
Krunal Rohit 17-Mar-14 2:41am    
Why why ???
I forgot to mention this in the answer. If you have n-nodes, then why would you update the count i.e to make it n+1 nodes ?
You get the count as many nodes you have in your XML.

-KR
KUMAR619 17-Mar-14 2:43am    
Yes Sir I got the count but the header tag

count="0"


Console.WriteLine(nodeCount); gets me the count.

But I want the header content change its count as the nodeCount value
Krunal Rohit 17-Mar-14 2:45am    
On some timer interval ??

-KR
KUMAR619 17-Mar-14 2:46am    
That means

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900