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
1975 Views

Similar Articles

[PageSpeed] 37

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:

Count Queries in a Database
I need an example of how to count the number of Queries that I have in a Database. I am using the code below; Where MSysObjects.Type = 5 (Represents QueryDefs). Dim db As DAO.Database Dim rst As DAO.Recordset Dim CmdExec As String Set db = CurrentDb Set rst = db.OpenRecordset("Select MSysObjects.Name From MSysObjects Where (((MSysObjects.Type)=5) And (InStr([NAme],""~"")=False);") The syntax is incorrect, but I cannot figure out what the machine wants. Also should I be useing QueryDefs in my code some place? ...

Inventory Count Unit of Measure
I would like the ability to specify a unit of measure for inventory stock counts. Because of rounding, consumption units, bill of material, and other issues base units of measure can be very different than the purchasing units which leads to counting confusion. Especially true of length, area, weight, and volume measures. For instance I have items purchased and inventoried by 55 gallon drum and consumed in milliliters. To avoid rounding and other issues, the base unit of measure is milliliters. I would like to be able to specify the inventory unit of measure for stock counts s...

counting based on two dates
I have two columns which both contains dates. I want a count based on criteria from the dates. For example... Start Date End Date 01/01/08 12/31/08 3/15/07 12/01/09 5/5/09 10/01/09 10/01/08 How would i get a total count of items that started before 06/01/08 and ended after 06/01/09. it would be 1 in the example above. Thanks Try this =SUMPRODUCT((A2:A20>DATE(2008,6,1))*(B2:B20<DATE(2009,6,1))) Mike "AccessNoviceButTrying" wrote: > I have two columns which both contains dates. I want a count based on...

Subtotaling count and sum
Can't find steps to subtotal a list showing both count and sum of columns. Example, totaling a dollar column and also indicating the number of transactions. I can calc one or the other, but not both. I'm sure it can be done, just don't know how. Any suggestions appreciated....Hal --- Message posted from http://www.ExcelForum.com/ Have a look at help for =subtotal(). It has a bunch of options for the first parameter. One will count, one will sum, one will countA and about 8 more! =subtotal(2,a1:a10) will count the number of numbers =subtotal(9,a1:a10) will sum the value...

Summing/counting data when columns match each other
I've got Worksheet1 with all my data, though only 4 columns of eac entry matter. For clarity's sake, I've got a separate worksheet calle "Summary," which is where I want to put all my commands. In Worksheet1, column D is the billing company, column F is the bille company, column H is the the category of thing sold, and column Q i the price. In Summary, I'd like to generate a row for every company that did an billing. Column A: name. Column B: Value of sales to themselves. Column C: Number of sales to themselves they did. Column D: Value o total sales. Colum...

Counting nubmer of months with correct year..
Hi everyone, I have a range of cells A1:A10, lets say, that contain delivery date for some product. These date can vary from say January to December of 2004 to 2008. The format is" MM/DD/YYYY). I like to write a formula that counts how many delivery dates is scheduled this month for this year. So the idea is that in Cell B1, I will type today's date. Then I like the formula to tell me how many delivery is scheduled (from the range A1:A10) that has this month and this year typed-in. I tried several things but without success. Any help please? Thanks Arpa. =SUMPRODUCT(--...

Count #13
Hi I want to count the number of instances a comma "," appears in one cell For instance Xxxxx xxx, xxxxxx xxx xxx xx, xxxxxx xxx xxx etc =2 or Xxxxxxxxxxxxx, xxx xx x xxxxxx xxx xxx, xxxx xxx xxx, =3 How do I write this please Garry Hi Garry, Am Thu, 19 Jan 2012 14:17:47 -0000 schrieb Garry: > For instance Xxxxx xxx, xxxxxx xxx xxx xx, xxxxxx xxx xxx etc =2 > or Xxxxxxxxxxxxx, xxx xx x xxxxxx xxx xxx, xxxx xxx xxx, =3 yourcell is A1, then try: =LEN(A1)-LEN(SUBSTITUTE(A1,",",)) Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /20...

Count new emails, appointments
I need to programmatically count the total number of new emails and total number of today's appointments in my calender. What is the bestway to do it? Note: I have to display it as a sharepoint webpart. Thanks for any input. J Justin ...

Count If Cell Value Starts with...
I need to count the number of cells in a range whose leftmost character is an S, or an L. I attempted to use the formula to count the cells starting with "S": {=SUMPRODUCT(LEFT(H7:H134,1)="S")} However it returned a zero, which is not correct. Does anyone know how I could do this without writing a VB custom function? Thanks! Scott Scott, The Boolean expression LEFT(H7:H134,1)="S" returns TRUE or FALSE. We need to coerce that to its equivalent 1 or 0 for SUMPRODUCT to add 'em up. An easy way is with double negation: {=SUMPRODUCT(--(LEFT(H7:H134,1)=...

counting embedded text #2
If I format the information with "Valid" or "Not Valid" first followe by an explaination, it works. The other option is to separate th status from the explaination. IE: have a separate column called vali and put a yes or no and count those. I only have about 45 entries s far, so it isn't that big of deal. So far, using the wildcard seems to be working -- Shocke ----------------------------------------------------------------------- Shocked's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1489 View this thread: http://www.excelforum.com...

count based on another field
I have a table in my database which records when a case is marked by an assessor. The table shows the case number, the assessor ID that the case has been assigned to and also an indicator to determine whether or not the case is closed. I need the query to show: The assessor ID number The number of cases assigned to a particular assessor the number of cases assigned to a particular assessor that are incomplete The first two are fine, however, how do I limit the last part of the query to show only the cases assigned to each assessor? thanks <barrynichols@gmail.com> wrote in message...

count function #2
Hi all How to count in Excel with 2 or more arguments Somthing like this =Countif (a2:a200 = "A" and B2:B200="B") Please Advise regards Kurt =SUMPRODUCT(--(A2:A200 = "A"),--(B2:B200="B")) For more details on SUMPRODUCT Bob Phillips http://www.xldynamic.com/source/xld.SUMPRODUCT.html J.E McGimpsey http://mcgimpsey.com/excel/formulae/doubleneg.html best wishes -- Bernard V Liengme Microsoft Excel MVP www.stfx.ca/people/bliengme remove caps from email "kurt" <google@haustrup.dk> wrote in message news:1e11c538-57af-423f-814b-692e4a8...

How to set specific regions and maintain running word count?
I'm writing a paper for a journal that wants to keep the total word count in some of the sections (but not others) below a certain number. Can I ask Word to keep (and display - in a header perhaps or a separate window or in the bar at the bottom of the document window) a word count of the total for the specific sections that I mark off? Mike In case you're not aware of it there are 2 ways if you merely need to 'check on' the count periodically. One options is in Word> Preferences> View, tick the checkbox for Live Word Count. This feature displays the numbe...

Payroll Employee Count and test company
We are approaching our max. # of employees b/c the system looks at live and test. KB article 885542 says you can change your company name - yet that field is greyed out. How to do i properly rename my company name to include <TEST> so my employee count is accurate. On Aug 6, 11:05=A0am, Andrea Smiley <AndreaSmi...@discussions.microsoft.com> wrote: > We are approaching our max. # of employees b/c the system looks at live a= nd > test. KB article 885542 says you can change your company name - yet that > field is greyed out. > > How to do i properly rename my compa...

counting number of cells where sum meets certain condition
1 50,000.00 2 (20,000.00) 3 (10,000.00) 4 (50,000.00) 5 2,000.00 6 10,000.00 7 10,000.00 8 30,000.00 9 20,000.00 Given the above data, how do I count the number of data until the sum starts going positive? manually, sum starts to be positive with the result 22,000 which is data no. 8. What formula do I use to get result 8? -- kugmo ------------------------------------------------------------------------ kugmo's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=35555 View this thread: http://www.excelforum.com/showthread...

Counting hours mins secs between 2 dates and times
Hello In my worksheet I have 4 columns. I have a start dates and end dates as well as times for start and end. I need to calculate the time elapsed between the start date and time till the end date and time. But it must display it as HH, MM, SS. I must show whether it has gone over 100 hours. That is the urgent level of my time frame I need it to look something like this Start Date Start Time End Date End Time Elapsed Time 06/01/2004 7:00 AM 6/08/2004 7:00 PM 144:55:24 I keep coming up with 00's Thanks Bob Use =(C2+D2)-(A2+B2) , but you'll need ...

Count by format
I want to count all the cells in a column that are filled in red. How do I type the formula? Thanks a lot in advanced! -- Josh Look here: http://www.cpearson.com/excel/colors.aspx -- Kind regards, Niek Otten Microsoft MVP - Excel "Josh" <jrivascamacho@hotmail.com> wrote in message news:A1069699-4E6C-4B9D-89F7-683C15ABD2E8@microsoft.com... >I want to count all the cells in a column that are filled in red. How do I > type the formula? > > Thanks a lot in advanced! > -- > Josh How did they get to be red? If by conditional formatting, count the valu...

Counting different colums
I am using this and it works perfectly: =COUNTIF('Issues Registered'!(P:P,"yes") But I want it to look in another column as well (Count "Yes" in colum P and all "1" in column G). What am I doing wrong? =COUNTIF('Issues Registered'!(P:P,"yes")(g:g,"1")) Your help will be appreciated Mike : -- gadge ----------------------------------------------------------------------- gadget's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2864 View this thread: http://www.excelforum.com/showthread.php?thread...

Lookup and count in the same formula
Hello, I need a formula that looks up a value in row 1 on sheet2 and returns the count of a range in the colmun that matches the lookup in sheet1. For example: Sheet2 - Feed Sheet Smithfield RSM John Doe ASM Jenn Smith ASM2 Brian Smith So Smithfield has 1 RSM and 2 ASMs Sheet1 RSM ASM Smithfield 1 2 So I want a formula to return the count of how many RSM's and ASM's are in a specific location. I have this: =(HLOOKUP(A1,Sheet2!A1:A6,(COUNTA(Sheet2!A5:A6)),FALSE)) but it's just retur...

Outlook 2003 Send/Receive Count
Just upgraded from Office XP to Office 2003, and finished installing all Office 2003 updates. When sending/receiving, Outlook 2003 shows the progress bar, but doesn't show the message count like previous versions of Outlook do. Is there a way to enable this somehow, or is this the way it is with Outlook 2003? Thanks!!! Toni;685870 Wrote: > Just upgraded from Office XP to Office 2003, and finished installing all Office 2003 > updates. > > When sending/receiving, Outlook 2003 shows the progress bar, but doesn't show the > message count like p...

Counting the number of rows between identical data.
Hello, I have a spreadsheet that lists the number of F1 races and the drivers who won those races. I'm trying to count the races that elapsed between wins. Column B contains the race #: (from 1 through 754) Column L has the race winners. In Column M, I want to count how many races it's been since a driver last won a race. For example: Giancarlo Fisichella won his 2nd race at the 2005 Australian G. P. (Race # 732) He won again at the 2006 Malaysian G. P., (Race # 753), 20 races had elapsed. Is there a formula I can use in Column M that will display 20? Thank you for you...

Counting occurences of time it takes to calculate to 0 or just ove
I am using Excel 2003 and I would like to create a formula to perform the following calculation. Cell E1 = 100,000.00 Cell E2 = 20,021.88 I would like the formula in Cell E3 If you subtract E2 from E1, update E1 as you go along, how many times do you have to do this to eventually make E1 = zero or a little more than zero? Here is my example: 100,000.00 - 20,021.88 = 79,978.12 (Count = 1) 79,978.12 - 20,021.88 = 59,956.24 (Count = 2) 59,956.24 - 20,021.88 = 39,934.36 (Count = 3) 39,934.36 - 20,021.88 = 19,912.48 (Count = 4) 19,912.48 - 20,021.88 = -109.4 Therefore, the answer shou...

how to sum up or count based on dates
Let say I have this file will multiple sheets: Bob, Adam, Shiela This example in Bob sheet: Date Activities Venue 3/19/2006 Parents Meeting Branch 3/25/2006 Area Meeting A HQ 4/3/2006 Clients Orientation Branch 5/11/2006 Team Meeting HQ Adam: Date Activities Venue 2/8/2006 Clients Oreintation Branch 3/25/2006 Area Meeting B HQ 4/17/2006 Team Meeting HQ...

Can children calendars trickle upwards to parent calendars?
Outlook XP/2002, Exchange Server 2000 I'm trying to arrange a Public Folder hierarchy that keeps company projects organized. Each project has its own folder, and each project folder has its own Calendar. I'd like to have a maintenance-free top-level Calendar that automatically shows all items from all project calendars beneath it in one view, so everybody can have a one-stop at-a-glace look at what's coming up for any project, without having to consult each project's calendar individually. Is this possible? If not possible with Exchange Server 2000, 2003 maybe? -- Jeff S....

Excel formula
I have 3 columns, one (A) is a list of countries, the second (B) is a list of the continents they are in and the final (C) is the years in which that country was visited. I want to be able to count the (B) column only if it has a year in the (C) column. Eg there might be 100 countries in column (A), 20 of which are in Europe(indicated in column (B) but only 10 have a year next to them in column (C) I want to work out in a seperate cell how many European countries have been visited .....hope that makes sense!!! --- Message posted from http://www.ExcelForum.com/ something like =sumproduct((...