Counting children

 Hi,

I'm struggling to find a way to count all children per level in an xml source.

Source:
<SWITCH-RDM port="BSC:BEERM-RBL2:107">
    <S1464 port="BSC:BEERM-RBL2:107" />
    <S1465 port="RXI:RX1RM-ETMC41:MS1-14-30" />
    <S1469 port="BSC:BEERM-RBL2:251" />
    <S6651 port="RXI:RX4RM-ETMC41:MS1-8-05">
        <S0287 port="RXI:RX4RM-ETMC41:MS1-8-05">
            <S0542 port="RXI:RX4RM-ETMC41:MS1-8-05">
                <S1473 port="RXI:RX4RM-ETMC41:MS1-8-05" />
            </S0542>
        </S0287>
    </S6651>
    <S6651 port="RXI:RX4RM-ETMC41:MS1-8-06">
        <S0287 port="RXI:RX4RM-ETMC41:MS1-8-06">
            <S0542 port="RXI:RX4RM-ETMC41:MS1-8-06" />
        </S0287>
    </S6651>
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-43">
        <S1479 port="RXI:RX2RM-ETMC41:MS1-12-43" />
    </S0376>
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-44" />
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-45" />
    <S0376 port="RXI:RX2RM-ETMC41:MS1-12-46" />
    <S0037 port="RXI:RX3RM-ETMC41:MS1-18-01">
        <S2358 port="RXI:RX3RM-ETMC41:MS1-18-01">
            <S1532 port="RXI:RX3RM-ETMC41:MS1-18-01" />
        </S2358>
    </S0037>
</SWITCH-RDM>

So what I'm trying to do is: 
- count how many childnodes are in SWITCH-RDM,but only the ones directly in 
it, not the childnodes' childnodes.
- Count how many childnodes there are in each childnode

If I do SelectNodes("Switch-RDM").count I get the result of 1.
If I do SelectNodes("*").count I get all the nodes.

please help with this.

rg,
Eric

0
Eric1 (389)
10/18/2009 4:56:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
1877 Views

Similar Articles

[PageSpeed] 41

Eric wrote:
>  Hi,
> 
> I'm struggling to find a way to count all children per level in an xml source.
> 
> Source:
> <SWITCH-RDM port="BSC:BEERM-RBL2:107">
>     <S1464 port="BSC:BEERM-RBL2:107" />
>     <S1465 port="RXI:RX1RM-ETMC41:MS1-14-30" />
>     <S1469 port="BSC:BEERM-RBL2:251" />
>     <S6651 port="RXI:RX4RM-ETMC41:MS1-8-05">
>         <S0287 port="RXI:RX4RM-ETMC41:MS1-8-05">
>             <S0542 port="RXI:RX4RM-ETMC41:MS1-8-05">
>                 <S1473 port="RXI:RX4RM-ETMC41:MS1-8-05" />
>             </S0542>
>         </S0287>
>     </S6651>
>     <S6651 port="RXI:RX4RM-ETMC41:MS1-8-06">
>         <S0287 port="RXI:RX4RM-ETMC41:MS1-8-06">
>             <S0542 port="RXI:RX4RM-ETMC41:MS1-8-06" />
>         </S0287>
>     </S6651>
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-43">
>         <S1479 port="RXI:RX2RM-ETMC41:MS1-12-43" />
>     </S0376>
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-44" />
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-45" />
>     <S0376 port="RXI:RX2RM-ETMC41:MS1-12-46" />
>     <S0037 port="RXI:RX3RM-ETMC41:MS1-18-01">
>         <S2358 port="RXI:RX3RM-ETMC41:MS1-18-01">
>             <S1532 port="RXI:RX3RM-ETMC41:MS1-18-01" />
>         </S2358>
>     </S0037>
> </SWITCH-RDM>
> 
> So what I'm trying to do is: 
> - count how many childnodes are in SWITCH-RDM,but only the ones directly in 
> it, not the childnodes' childnodes.
> - Count how many childnodes there are in each childnode
> 
> If I do SelectNodes("Switch-RDM").count I get the result of 1.
> If I do SelectNodes("*").count I get all the nodes.

If you are interested in the _element child nodes_ of the root element 
then use e.g.
XmlDocument doc = new XmlDocument();
doc.Load("file.xml");

and then

int count = doc.SelectNodes("SWITCH-RDM/*").Count;

or

int count = doc.DocumentElement.SelectNodes("*").Count;

There is also a ChildNodes collection but that will contain all kind of 
nodes (i.e. element nodes but comment and processing instruction nodes 
as well and even text nodes with white space if PreserveWhitespace on 
the document has been set).

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1777)
10/18/2009 5:28:13 PM
Reply:

Similar Artilces:

Dialog in taskbar steals focus from children
I have a dialog in my application that I want to be shown in the taskbar (it's not the main window). I do this by calling this in OnInitDialog: ::SetWindowLong( m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE)|WS_EX_APPWINDOW ); This works quite well but there is one minor bug. If that dialog has a children, for example a message box, the message box doesn't get the focus when the user click on the button in the taskbar. Instead the dialog receive the focus. If the user use Alt+Tab or trying to click on the dialog, the message box gets the focus as expected. Any suggestion...

Help with counting rows
I have a datafeed that comes to me everyday via email , every day the feed had slighty different rows as it has different updated products i.e. somedays 999 , 1001 etc. What i need to do is run a macro so when the excel file arrives to count the number of rows and then add the letter "y" in a 3 new columns . At the moment i have to do it manually is this easy to do Paul iLastRow = Range("A1").End(xlDown) Range("B1").Resize(iLastRow,3).Value = "y" -- HTH Bob Phillips (remove nothere from email address if mailing direct) <plm11111@h...

Counting the number of sessions in a web farm
Hi, We have a ASP .NET application which will be deployed in a web farm. We would like to find the total number of sessions that have been established. If we create a counter in global.asax.cs, it will be able to count only within aspnet_wp process. In a web farm, multiple nodes will have IIS on multiple machines. If we use SQL server-based session management, can we get the total number of active session by querying the Session DB? If we later decide to use session state server to store the sessions, can we get the number of active sessions? Thanks, Yash ...

Stock Count Schedules
Does anyone know what tables the stock count schedules are located in? Our schedules are manually created line by line and we have 15 different schedules. I would like to physically copy these files so I can replace them if needed. Vinnie Not a bad plan, the two tables you want are IV10300 and IV10301. If you have serialized or lotted items or multiple units of measure, copy also IV10302 and IV10303. Be sure to visit our booth in Convergence, #624 -- Richard L. Whaley Author / Consultant / MVP Documentation for Software Users For help learning and better using Dynamics GP,... check...

Query Does Not Count "2" Records
Good Evening Everyone... I have a bit of a logical puzzle that I need to solve. I have various queries which have various criteria for them. One query involves retirees or spouses being under the age of 65 and the other involves retirees or spouses being over the age of 65. Both the retiree and spouse are listen in the same records and on one line of the master table and queries. The situation that I am running into is that I can have a retiree who is over 65 and a spouse under 65 and the record comes up twice in the two different queries b/c it meets the criteria, which is perfect. What...

how to count email bytes
Hi NG, I want to measure the amount of emails flowing to our system in one day. With the ESM, I am able to view emails depending on date and the ESM display the size of every email. Is there a possibility to copy the query result in a text file? Or is there another way to get the quantity of all emails per day? Thanks in advance, Birte Have a look at some of the Perfmon counters for SMTP (Messages Received total, Messages Sent total, etc). They ought to be able to get you the rough statistics you are looking for. The bad news here is that I believe in order to reset the perfmon counte...

counting numbers if certain criteria are met?
I have two columns. the first has single digits between 0 and 9, th second has x's with blank spaces in between. Anyone know how to count or mark all the 2's in the first column that also have an x in th second column? Don't want to just count ALL the 2's -- Message posted from http://www.ExcelForum.com Hi Try something like this: =SUMPRODUCT((A2:A1000=2)*(B2:B1000="x")) -- Andy. "judoist >" <<judoist.17uhhk@excelforum-nospam.com> wrote in message news:judoist.17uhhk@excelforum-nospam.com... > I have two columns. the first has single ...

Count feature
I have Excel 2000. I have blank cells and cells with text data (not numbers). I want to count the number of cells in a range that have data in them and to have the blank cells not be counted. What is the function for this? Thanks! Kathy Kathy, use counta, like this, =COUNTA(A1:A10) -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "Kathy" <Kathy@discussions.microsoft.com> wrote in message news:81303BCE-4BDA-48F0-...

COUNT multiple ranges
Hi Guys This formlua has has me stumped, what I am trying to do is... IF the data in column B equals say POP & the data in Column C equals JOP that entry receives a count (both entries must be on the same row to receive a count) example data A B C D E 1 POP JOP 2 PPP JOP 3 POP GUP 4 POP JOP 5 YUP KUP 6 POP JOP So the above table would return the count of 3 any help will be appreciated =SUMPRODUCT(--(B1:B6="POP"),--(C1:C6="JOP")) -- HTH RP ...

How do I count the cells ending with a specific letter?
Hi, I am trying to count the cells in a column ending with a particular letter. Cells contain alphanumeric values. For ex: =COUNTIF(W5:W7,"*P") This is giving zero as the answer instead of 2. Please help.. =COUNTIF(W5:W7,"=*P") "David" wrote: > Hi, > > I am trying to count the cells in a column ending with a particular letter. > Cells contain alphanumeric values. For ex: =COUNTIF(W5:W7,"*P") This is > giving zero as the answer instead of 2. Please help.. > > Nope not working Ronaldo :( "RonaldoOneNil" wrote: &g...

Sales for outlook
I suppose there is no way to show relation ships of family members? Antony Antony, Currently, MS CRM does not track so-called "network" relationships. There are a few ISV products that will allow this, and it sounds like this will be something that you could add in v2.0 using the expanded customization capablities. Matt Parks ---------------------------------------- ---------------------------------------- On Thu, 10 Jun 2004 07:25:55 -0700, "Antony" <anonymous@discussions.microsoft.com> wrote: I suppose there is no way to show relation ships of family members...

search of a string in a cell and counting occurences using COUNTIF
i need to separate out items which are in a column with cells containing 1 or more of these items delimited by commas. i need to export them to another worksheet within the spreadsheet which lists down the items individually per cell and then, i need to count the occurences. i tried to use the asterisk i.e. '*cell_contents*' in the countif formula but i get an error. please help! ** Posted via: http://www.ozgrid.com Excel Templates, Training, Add-ins & Business Software Galore! Free Excel Forum http://www.ozgrid.com/forum *** To whom it may concern, I do not know what your questi...

Counting an entry to a cell
Using Excel 2007 I would like to get a formula that will allow me to count entries in column C, but if an entry is made in column D that would supersede what is in column C. When an entry is made into column H I would like the total for columns C or D to reflect this i.e. total number counted should drop. I have listed names at top of s/sheet and totals are to sit in H1, H2 etc. Hope you can assist. Let me know if you require additional info. Cheers, Paul You have an answer at your duplicate posting - please do not multi- post. Pete On Aug 7, 10:25=A0am, slavenp <slav...@discussi...

Counting text in a column
I used to think I was good at Excel until this stumped me. I have a column with a variety of text in each cell. Example: A1 bob bob ted ted ted charley charley charley charley, etc. Is there a formula or way I can take the whole column of data and hav it come back with something similar to: bob = 2 ted=3 charley=4 etc. for all the variables in the column? Please help, I am dying over here -- prom4 ----------------------------------------------------------------------- prom4x's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2901 View this thread: http://www...

Count only 315 and higher? Count shaded cells?
Hi there, I wonder if some kind soul can help me on these two issues please? I am currently using the formula =COUNT(P2:P21) to count the number of entries in a column. However I now have a need to only count those cells that contain the cost 315 and higher - i.e. ignoring anything under 315 How do I do this? Is it simply a case of altering my formula to read =COUNT(P2:P21 <315) or is there a better/proper way to do it? On a separate issue is there a way to total up the cost of only those cells that are shaded - i.e.. when I reconcile an invoice I shade the box grey to distinguish it...

Student count for Class Registration
Hi, The goal / Issue: I want to be able to register the student right after the user enters the student name and address. Currently, the user does this by simply clicking on the Registration tab and registering the student. While I know the maximum number of students allows in the class, I don’t know how to check the current count to determine if the class is open or closed based on the student count. Normally, I would cheat and have a field which is a count of the current number of registered students. But I was hoping that is a better way to do this in Access. ...

Stock count of serial numbered items
I have recurring issues with serial-numbered items and stock count entry. For instance, in my stock count I have a serial-numbered item with a captured quantity of 1. My counted quantity is zero. Therefore, I should have a variance of -1. I go into the Stock Count Serial Number Entry window and change the Count Status to Not Found for my one serial number. When I click on OK, I get "The variance or counted quantity for this serial number does not equal the variance or counted quantity for the item - Continue, Override, Cancel". If I click on Override, I get "The calc...

How do I count selected data in a report footer
Am attempting to count the number of conditions in a data field [status] with a certain stated value; in a group summary and then a report summary (i.e. count the Number of records where the data in [status] equals a descriptive value such as “Widow”, “Active”, or “Retired”). Just as Douglas Steele said in the earlier posting, use something like the following for the control's source =Abs(Sum([Status]="Widow")) You will need a control for each status and, obviously, you will need to change the value you are looking to count. '=========================================...

Money 2006: Downloaded Transaction Issue-Double Counting
I am using Money 2006 and just signed up for electronic downloads of my bank and credit card statements. My wife pays the credit cards through my banks web-based service. Then when the bank and credit card download directly into money-there is an electronic credit card payment from the bank and the credit card company receives an electronic payment. The problem is that the credit card transactions get categorized (from the credit card download) and the credit card payment (from the bank) is one lump sum expense and thus essentially double counting my expenses. I tried doing the spec...

Counting Records in Excel?
Basically... I'm trying to figure out how to do something in Excel that could readily be done in MS Access. I have an Excel list, and I want to know how many records contain "Chicago" in one of the fields. I thought up this array formula: =SUM(IF(F2:F1123="chicago",1,0)) The idea is that, for every cell containing "chicago," Excel would enter a "1" in a duplicate range and a "0" if the cell didn't contain "chicago." Excel then would add up the ones and tell me how many records in the list were from...Chicago. This d...

Array Formula isn't summing but counting
I need to sum information based on several other criteria -- accoun number, sort codes, company names. The array formul {=SUM(A1:F25="A")*(E1:E25>0))} returns a count rather than a sum Does anyone know of a way get it to add my data rather than countin how many? Staci -- Message posted from http://www.ExcelForum.com Hi if you want to sum column E try the array formula =SUM((A1:F25="A")*(E1:E25>0)*(E1:E25)) or a non array formula =SUMPRODUCT((A1:F25="A")*(E1:E25>0),E1:E25) -- Regards Frank Kabel Frankfurt, Germany > I need to sum information ...

Counting Dates #2
What's the easiest way to count the unique number of days in a list of dates: 1/23/09 1/23/09 1/23/09 1/24/09 1/25/09 1/26/09 1/26/09 1/26/09 1/26/09 Answer should be 4. JimS wrote: > What's the easiest way to count the unique number of days in a list of > dates: > > 1/23/09 > 1/23/09 > 1/23/09 > 1/24/09 > 1/25/09 > 1/26/09 > 1/26/09 > 1/26/09 > 1/26/09 > > Answer should be 4. If your dates are in A1:A9 the result is =SUM(IF(FREQUENCY(A1:A9,A1:A9)>0,1)) Very slick, thanks. On Sat, 24 Jan 2009 20:53:08 -0500, smartin <smartin108@g...

Count Rows When Using Auto-Filter
Using the auto-filter function I need to count the number of rows returned each time I select a new value. I can do a COUNTA (&#8211;1 to allow for the header row), on the column that counts all the rows but when I use the filter I still get the total count not a count of the reduced quantity by the filter. Can anyone help? Nick use the subtotal function with a first argument of 3 =subtotal(3,A2:A300) as an example. Make sure the column you do the counta on will have values in all rows. -- regards, Tom Ogilvy "Nick" <ner@westnet.com.au> wrote in message news:15...

How do I count If for these special distinctions
I need to count the number of names in a very long list complaring excel columns that are titles name and date. I would like the formula to count all DISTINCT names on EACH given date giving me a grand total of names. EXAMPLE James Smith June 12, 2004 James Smith June 12, 2004 Mike Black June 12, 2004 Karen Jones June 13, 2004 Mike Black June 13, 2004 Jane Smith June 13, 2004 Total Count: 5 I appreciate the help. Thank you. I don't quite understand your explanation of where the date comes into the picture, but t...

Counting cases between dates
Hi, I am using a waiting list of our clients and i would like to be able to calculate how many are on the list, from todays date, that have been waiting less than 6 weeks, 6 - 18 weeks and 18 weeks+. I would be very grateful for any help with this as it's driving me mad :( -- Many thanks, Lisa Hi Lisa Suppose you have the dates in ColB try the below 'Count of clients waiting for the last 6 weeks =COUNTIF(B:B,">" & TODAY()-(6*7)) 'Count of clients waiting for the last 6 - 18 weeks =COUNTIF(B:B,">" & TODAY()-(18*7))-COUNTIF(B:B...